Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Formatting a date under NT/2k/XP

1 view
Skip to first unread message

Simon Sheppard

unread,
Mar 17, 2002, 1:57:14 PM3/17/02
to
crossposted to microsoft.public.win2000.cmdprompt.admin

On Tue, 19 Mar 2002 14:37:02 -0000, "Ritchie Lawrence"
<rlaw...@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?
>
>========================== 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@ "
-

Alex K. Angelopoulos

unread,
Mar 19, 2002, 2:53:15 PM3/19/02
to
Works fine on XP Pro, of course:

Year=[2002] Month=[03] Date=[19]


"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c94e4d...@news.demon.co.uk...
: crossposted to microsoft.public.win2000.cmdprompt.admin

0 new messages