Running Windows 2000 SP4. Regional setting on both Short and Long date are
set to dd/MM/yyyy
In command prompt, when entering echo %date% it gives
Wed 04/10/2006
Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy
On XP SP1 or SP2 are fine, the date display correctly. The problem is
causing havoc on our application passing the date info.
> Hello,
>
> Running Windows 2000 SP4. Regional setting on both Short and Long date are
> set to dd/MM/yyyy
>
> In command prompt, when entering echo %date% it gives
> Wed 04/10/2006
>
> Is there a way to get rid of the Wed (day part), I just want the dd/MM/yyyy
echo %date:~4%
How can I set this permanently or at least using script. We only have 5-6
of these windows 2000 machine that have this problem.
Thanks,
> How can I set this permanently or at least using script. We only have 5-6
> of these windows 2000 machine that have this problem.
Show me your script and I'll take a look.
> Thanks,
yw.
I was hoping you know some set command, I don't have any script at hand.
Any help, greatly apprecaited.
V
> Hello,
>
> Running Windows 2000 SP4. Regional setting on both Short and
> Long date are set to dd/MM/yyyy
Not your answer, but I strongly suggest Date be formatted in an ISO-
compliant and worldwide understandable format such as:
YYYY-MM-DD
which also make sorting by date and date math much easier.
Essentially, you can't.
%date% and %time% are set up by the OS and evaluated at the time of
execution. You CAN set an environment variable "date" (or "time") to
anything you want, and this value then overrides the "system" value until
the USER value is deleted (set to null) but I don't think that helps too
much here..
Here's a demo using "time" (which has a habit of changing faster than
"date") :
----- batch begins -------
[1]@echo off
[2]for /l %%i in (1,1,3) do echo %time%&call :later
[3]for /f "tokens=1,2" %%i in ( ' date /t ' ) do if [%%j]==[] (set yds=%%i)
else (set yds=%%j)
[4]echo %yds%
[5]goto :eof
[6]
[7]:later
[8]echo time is %time%
[9]:: set time=user
[10]echo time is %time%
[11]ping -n 2 127.0.0.1 >nul
[12]goto :eof
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped
and should be rejoined. The [number] that starts the line should be removed
The label :eof is defined in NT+ to be end-of-file but MUST be expressed
as :eof
The spaces surrounding the single-quotes are for emphasis only. The SPACES
are not required but the single-quotes ARE required.
With this demo, with line [9] as a comment, and [11] is a 2-second delay,
there are three reports of 3 lines each
* original-time when [2] was commenced
* time when [8] is executed
* time when [10] is executed
This demonstrates that [2] produces the parse-time value (a well-established
principle) and shows that indiscriminate use of %time% (and by extension,
%date%) can cause problems because it CAN change within a script.
If you then take the leading "::" from line [9] then the report changes:
* original-time when [2] was commenced
* time when [8] is executed
* user
* original-time when [2] was commenced
* user
* user
* original-time when [2] was commenced
* user
* user
which shows that the environment value set by the USER overrides that
supplied by the system.
Note however that [3] will correctly set YDS (your Date String) to the
correct value, regardless of whether the format had a leading dayname.
Hence [3] may be used on both XP and 2K (restoring commonality) to establish
the date-string to be used; possibly by substituting "date" for "yds" OR by
using "%yds%" in place of "%date%" in your batches - provided [3] is
executed at the start of each %date%-using batch. "yds" naturally can be
any variable-name you choose.
I use Ritchie Lawrence's GetDate routine for this issue. It returns the date
in whatever format you want. For your example, this will get you what you
want.
@echo off & setlocal
call :GetDate y m d
echo %m%/%d%/%y%
goto :eof
:GetDate yy mm dd
setlocal & set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
"vince" <vi...@discussions.microsoft.com> wrote in message
news:8DFCDA27-EA7E-4FFC...@microsoft.com...
--
Posted via a free Usenet account from http://www.teranews.com
>If Regional Date format setting is m/d/yy or similar (note yy option) these
>examples discussed of Date/t and %date% fail. These examples are fine when
>Regional Date format setting is m/d/yyyy or similar (note yyyy option). How
>do I get guaranteed for digit year using MS-Dos? Thanks
:: DateTime - WMIC
@echo off
:: info based on usenet post by ten.n...@virgin.net
:: 18 Aug 2008 22:29:38 +0100,
:: xp and higher
(
Wmic Path Win32_LocalTime Get day,hour,minute,month,second,year /value
)>%temp%.\wmicinfo.txt
for /f "delims=" %%a in ('type %temp%.\wmicinfo.txt') do set %%a
del %temp%.\wmicinfo.txt
set Day=00%day%
set Hour=00%hour%
set Minute=00%minute%
set Month=00%month%
set Second=00%second%
set Day=%day:~-2%
set Hour=%hour:~-2%
set Minute=%minute:~-2%
set Month=%month:~-2%
set Second=%second:~-2%
set yr=%year:~2%
echo Hour=%hour%
echo Minute=%minute%
echo Second=%second%
echo Day=%day%
echo Month=%month%
echo Year=%year%
echo Yr=%yr%
pause
Control Panel > Regional and Language Options > Regional Options "tab" > "Customize"
button
...and [re]set short date (middle box) to dd-MM-yy (instead of ddd dd-MM-yy)
Also change date "separator" from here as this may also cause your application to
malfunction.
==
Cheers, Tim Meddick, Peckham, London. :-)