Hi All, After further deliberation, I now propose the following, for retrieving the date on NT/2K/XP, independant of regional settings. Anyone care to test it?
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))
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c8a3e60.997213@news.demon.co.uk... > On Sun, 17 Mar 2002 22:13:42 -0000, "Ritchie Lawrence" > <rlawre...@commanddoline.co.uk> wrote:
> >It was covered, you've re-written my post with two periods.
> Sorry - I can't believe I posted that - I must have been having an > 'off day' yesterday
> Anyway I tested this again at work today
> The first thing I noticed is that XP outputs the date in a different > format...
> C:\>ver > Microsoft Windows XP [Version 5.1.2600]
> C:\>date/t > 18/03/2002
> C:\>echo.|date > The current date is: 18/03/2002 > Enter the new date: (dd-mm-yy)
> C:\>echo %date% > 18/03/2002
> So here's a variant of your script adjusted to run under NT, W2k and > XP - all lines indented 3 chars
> @echo off&setlocal > for /f "tokens=1-4 delims=/-. " %%G in ('date /t') DO call > :s_fixdate %%G %%H %%I %%J > goto :eof
> :s_fixdate > :: Adjust for Win XP > SET/a part1=%1 > if %part1% EQU 0 shift
> :: Save the day month year > SET part1=%1 > SET part2=%2 > SET part3=%3
> :: Figure out which part is which
> for /f "skip=1 tokens=2-4 delims=(-)" %%G in ('echo.^|date') do ( > for /f "tokens=1-3" %%U in ("%part1% %part2% %part3%") do ( > set %%G=%%U > set %%H=%%V > set %%I=%%W > ) > ) > ::print the resulting date > echo Month: [%mm%] > echo Day: [%dd%] > echo Year: [%yy%]
> I have briefly tested this under all 3 platforms with UK, French and > German date formats.
> The first SET statement should evaluate any text "Mon, Tue, Wed..." to > 0 so we can test for this without knowing or relying on any specific > spelling which may be locale specific. > - > Simon Sheppard > Web: http://www.ss64.com > email: Simon@ " > -
<rlawre...@commanddoline.co.uk> wrote: >Hi All, >After further deliberation, I now propose the following, for >retrieving the date on NT/2K/XP, independant of regional >settings. Anyone care to test it?
>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))
<garrydeane_at_yahoo.com.au> wrote: >NOTES >1) The "NET TIME \\machinename" command in Win XP ALWAYS gives date & >time in a variant of the US date and time format, e.g. 5/23/2000 2:07 >PM, regardless of the Regional Options.
>John Gray 16-23OCT2001, 11-13FEB2002
This may be an easier method - though NET TIME requires the SERVER service to be running (on %computername% ) the script below only returns a 2 digit year, and it removes some leading zeros
@echo off&setlocal
FOR /f "tokens=6-9 delims=/ " %%G IN ('NET TIME \\%computername%') DO ( SET v_mm=%%G SET v_dd=%%H SET v_yy=%%I SET v_time=%%J)
ECHO Today is Year: [%v_yy%] Month: [%v_mm%] Day: [%v_dd%] Echo The time is [%v_time%]
: : >Hi All, : >After further deliberation, I now propose the following, for : >retrieving the date on NT/2K/XP, independant of regional : >settings. Anyone care to test it? : > : >========================== getdate.cmd ========================== : >@echo off&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)) : > : >echo Year=[%yy%] Month=[%mm%] Date=[%dd%] : >================================================================= : > : >If I can find a list of the various regional outputs, I think it : >should be possible to get it back to a one-liner. : > : >-- : >Ritchie : : Interesting - here's something similar I tested today with a variety : of dates and regional settings under NT/2k/XP : : @echo off&setlocal : for /f "tokens=1-4 delims=/-. " %%G in ('date /t') DO call : :s_fixdate %%G %%H %%I %%J : goto :s_print_the_date : : :s_fixdate : if "%1:~0,1%" GTR "9" shift : for /f "skip=1 tokens=2-4 delims=(-)" %%G in ('echo.^|date') do ( : set %%G=%1&set %%H=%2&set %%I=%3) : goto :eof : : :s_print_the_date : echo Month: [%mm%] : echo Day: [%dd%] : echo Year: [%yy%] : : - : Simon Sheppard : Web: http://www.ss64.com : email: Simon@ " : -
<rlawre...@commanddoline.co.uk> wrote: >Hi All, >After further deliberation, I now propose the following, for >retrieving the date on NT/2K/XP, independant of regional >settings. Anyone care to test it?
>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))
"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3c97d012.1442033@192.168.0.2... > On Tue, 19 Mar 2002 14:37:02 -0000, "Ritchie Lawrence" > <rlawre...@commanddoline.co.uk> wrote:
> >Hi All, > >After further deliberation, I now propose the following, for > >retrieving the date on NT/2K/XP, independant of regional > >settings. Anyone care to test it?
> >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))
> This won't work for NT, only W2k & XP automatically set %date%. For > NT, you need to do a prior FOR .. ('date/t')... to do this.
Hi Garry, you _DIDN'T_ test it then ;)
The other way I was thinking of was the same as that above, but scrap the first line, and add to the second delims all the characters that may be used for the DOW. Decided against because I've not been able to find what abbreviations are used for all DOWs in all regions.
I could just add the whole alphabet, but as the delims is case sensitive, that would 52 characters and even some regions don't used letters from the 'standard', so I'll stick with the script above.
<rlawre...@commanddoline.co.uk> wrote: >"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3c97d012.1442033@192.168.0.2... >> On Tue, 19 Mar 2002 14:37:02 -0000, "Ritchie Lawrence" >> <rlawre...@commanddoline.co.uk> wrote:
>> >Hi All, >> >After further deliberation, I now propose the following, for >> >retrieving the date on NT/2K/XP, independant of regional >> >settings. Anyone care to test it?
>> >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))
>> This won't work for NT, only W2k & XP automatically set %date%. For >> NT, you need to do a prior FOR .. ('date/t')... to do this.
>Hi Garry, you _DIDN'T_ test it then ;)
Oops - yeah you're right. Quite neat.
>The other way I was thinking of was the same as that above, but scrap >the first line, and add to the second delims all the characters that >may be used for the DOW. Decided against because I've not been able to >find what abbreviations are used for all DOWs in all regions.
>I could just add the whole alphabet, but as the delims is case sensitive, >that would 52 characters and even some regions don't used letters from >the 'standard', so I'll stick with the script above.