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

Formatting a date

1,422 views
Skip to first unread message

Perception

unread,
Mar 14, 2002, 6:36:54 PM3/14/02
to
I'm trying to format a variable with the following value:
"03/14/2002"

To the following value:
"20020314"

Any ideas?
-Perception


Phil Robyn

unread,
Mar 14, 2002, 7:11:35 PM3/14/02
to
Perception wrote:

Assuming that YOURVAR already contains "03/14/2002", you could do
the following:

set YOURVAR=%YOURVAR:/=%
set YOURVAR=%YOURVAR:~4,4%%YOURVAR:~0,4%

--

u n z i p m y a d d r e s s t o s e n d e - m a i l


Clay Calvert

unread,
Mar 14, 2002, 7:17:57 PM3/14/02
to

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
set ddate=%%c%%a%%b)

HTH

Clay Calvert
Replace "W" with "L" in email.

Clay Calvert

unread,
Mar 14, 2002, 7:37:00 PM3/14/02
to
On Thu, 14 Mar 2002 16:11:35 -0800, Phil Robyn
<pro...@uclink.berkzipeley.edu> wrote:

>Perception wrote:
>
>> I'm trying to format a variable with the following value:
>> "03/14/2002"
>>
>> To the following value:
>> "20020314"
>>
>> Any ideas?
>> -Perception
>
>Assuming that YOURVAR already contains "03/14/2002", you could do
>the following:
>
> set YOURVAR=%YOURVAR:/=%
> set YOURVAR=%YOURVAR:~4,4%%YOURVAR:~0,4%

Phil

Very nice!

Perception

unread,
Mar 14, 2002, 8:26:47 PM3/14/02
to
Wonderful! Worked like a charm!
-perception

"Phil Robyn" <pro...@uclink.berkzipeley.edu> wrote in message
news:3C913C37...@uclink.berkzipeley.edu...

Perception

unread,
Mar 14, 2002, 9:01:31 PM3/14/02
to
Thanks Clay!
I think I prefer Phil's method, but appreciate your post.

-Justin

"Clay Calvert" <ccal...@Wanguru.com> wrote in message
news:16f29ucl1uot1sp3b...@4ax.com...

Ron Lyman

unread,
Mar 15, 2002, 2:21:33 PM3/15/02
to
Clay Calvert <ccal...@Wanguru.com> wrote in message news:<16f29ucl1uot1sp3b...@4ax.com>...

This is how I do it. Problem is, when I move the script to a
different computer, with different system settings, the date format is
different, and my script breaks. i.e. on one Win2K Server I use
%%a/%%b/%%c and on the other Win2K Server I have to use %%c/%%a/%%b in
order to have output yyyy/mm/dd in both cases.

Do any of you have a trick for making this code more portable? I
suppose I could test for the length of %%a, %%b, and %%c, but maybe
there is a more elegant solution.

Regards,
Ron.

Ritchie

unread,
Mar 15, 2002, 3:25:06 PM3/15/02
to
"Ron Lyman" <lmnr...@tm1.at> wrote in message news:9a83f460.02031...@posting.google.com...

Hi Ron,
Here's some flexible code. Add/remove as many date
formats as you like.

-- Ritchie

================ start =============================
@echo off&setlocal

for /f "skip=1 tokens=3-6 delims=:(\-/)" %%a in (
'echo.^|date'
) do (
goto:%%a%%b%%c
)

:yymmdd
echo Get date in yymmdd format
goto:eof

:mmddyy
echo Get date in mmddyy format
goto:eof

:ddmmyy
echo Get date in ddmmyy format
goto:eof

:yyddmm
echo Get date in yyddmm format
goto:eof
=================== end ============================


Ritchie

unread,
Mar 16, 2002, 7:47:20 AM3/16/02
to
"Ritchie" <dontg...@enildnammoc.co.uk> wrote in message news:3c925...@mk-nntp-1.news.uk.worldonline.com...

> "Ron Lyman" <lmnr...@tm1.at> wrote in message news:9a83f460.02031...@posting.google.com...
> >
> > This is how I do it. Problem is, when I move the script to a
> > different computer, with different system settings, the date format is
> > different, and my script breaks. i.e. on one Win2K Server I use
> > %%a/%%b/%%c and on the other Win2K Server I have to use %%c/%%a/%%b in
> > order to have output yyyy/mm/dd in both cases.
> >
> > Do any of you have a trick for making this code more portable? I
> > suppose I could test for the length of %%a, %%b, and %%c, but maybe
> > there is a more elegant solution.
> >
> > Regards,
> > Ron.
>

Hi Ron,
My earlier post got me thinking (for once)...

Version II, which is effectively a one-liner, works on NT/2K
with every date format one could ever reasonably expect to
encounter. This is how I'll be retrieving dates from now on.

================== start getdate.bat =========================
@echo off&setlocal

for /f "skip=1 tokens=3-6 delims=:.(\-/)" %%a in ('echo.^|date') do (
for /f "tokens=2-4 delims=.\-/ " %%d in ('date /t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f
)
)

echo Month: %mm%
echo Date: %dd%
echo Year: %yy%

================== end getdate.bat ===========================

PS When testing don't forget to start a new cmd.exe after
changing regional settings.

-- Ritchie


Dr John Stockton

unread,
Mar 16, 2002, 7:21:21 AM3/16/02
to
JRS: In article <9a83f460.02031...@posting.google.com>, seen
in news:alt.msdos.batch.nt, Ron Lyman <lmnr...@tm1.at> wrote at Fri, 15
Mar 2002 11:21:33 :-

>
>This is how I do it. Problem is, when I move the script to a
>different computer, with different system settings, the date format is
>different, and my script breaks. i.e. on one Win2K Server I use
>%%a/%%b/%%c and on the other Win2K Server I have to use %%c/%%a/%%b in
>order to have output yyyy/mm/dd in both cases.

Use my NOWMINUS (via sig line 3); it has no interest whatsoever in any
system settings.

It can give the date in the following basic formats (all the same date,
01:02:03) directly :

2001-12-25
2001-52-02
0002452269
1009242123
2001-38-05
2001-09-20
2001-359
Tue, 25 Dec 2001
2001-4-86 4Q01 4Q2001
25-12-2001

For yyyy/mm/dd, use NOWMINUS j/ f1 r

--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS, EXE in <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm &c.

Simon Sheppard

unread,
Mar 16, 2002, 3:32:04 PM3/16/02
to
On Sat, 16 Mar 2002 12:47:20 -0000, "Ritchie"
<dontg...@enildnammoc.co.uk> wrote:

>Hi Ron,
>My earlier post got me thinking (for once)...
>
>Version II, which is effectively a one-liner, works on NT/2K
>with every date format one could ever reasonably expect to
>encounter. This is how I'll be retrieving dates from now on.
>

If you're interested there are a ton of posts on this topic in the
archive - the tricky thing is getting a reliable date that includes a
4 digit year:

http://groups.google.com/groups?selm=3bc48422.942835%40news.demon.co.uk&oe=ISO-8859-1&output=gplain

:: This batch file - based on a previous post by Michael Jerkovic
will return the date (including 4 digit year) into environment vars

:: Works on any NT machine independent of regional date settings

@ECHO off
SETLOCAL
IF [%1]==[] goto s_start

ECHO GETDATE.cmd
ECHO Returns the date independent of regional settings
ECHO Creates the environment variables %v_year% %v_month% %v_day%
ECHO.
ECHO SYNTAX
ECHO GETDATE
ECHO.
ECHO.
GOTO :eof

:s_start

FOR /f "tokens=2-4 skip=1 delims=(-)" %%G IN ('echo.^|date') DO (
FOR /f "tokens=2 delims= " %%A IN ('date /t') DO (
SET v_first=%%G
SET v_second=%%H
SET v_third=%%I
SET v_all=%%A
)
)

SET %v_first%=%v_all:~0,2%
SET %v_second%=%v_all:~3,2%
SET %v_third%=%v_all:~6,4%

ECHO Today is Year: [%yy%] Month: [%mm%] Day: [%dd%]

ENDLOCAL & SET v_year=%yy%& SET v_month=%mm%& SET v_day=%dd%

-
Simon Sheppard
Web: http://www.ss64.com
email: Simon@ "
-

Ritchie Lawrence

unread,
Mar 17, 2002, 9:44:42 AM3/17/02
to
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c93aa57...@news.demon.co.uk...

> On Sat, 16 Mar 2002 12:47:20 -0000, "Ritchie"
> <dontg...@enildnammoc.co.uk> wrote:
>
> >Hi Ron,
> >My earlier post got me thinking (for once)...
> >
> >Version II, which is effectively a one-liner, works on NT/2K
> >with every date format one could ever reasonably expect to
> >encounter. This is how I'll be retrieving dates from now on.
> >
>
> If you're interested there are a ton of posts on this topic in the
> archive - the tricky thing is getting a reliable date that includes a
> 4 digit year:

Hi Simon,
If it's to do with NT batch, I'm always interested. By 'archive' do
you mean Google, or is there some another place?

Unless I've misunderstood you, I don't see whats tricky about getting a
4 digit date, as you know its part of the 'date /t' output.

I also considered a solution like yours where the separator character
(SC) is irrelevant, but decided against it as I felt it is more likely
to fail had a user been 'playing around' with the SC.

Reason being, anyone crazy enough to change the SC may just as well have
decided to use more than one character, for example '--' or '~#~',
causing any script that assumed a single SC to fail.

Of course, '~#~' would cause my solution to fail as it stands (although
'--' would be fine), but adding extra characters to my "delims" (omitted
from my OP for clarity) is all that's required.

Taking these arguments to their extreme, one could append all non numeric
characters to the "delims", keeping my solution a one-liner. On the other
hand, a solution that catered for a 1, 2 or 3 character length separator
would require additional coding.

All aspects considered, I maintain my earlier post stands as the
preferred solution.

--
Ritchie
Undo my address for email

Simon Sheppard

unread,
Mar 17, 2002, 3:27:18 PM3/17/02
to
On Sun, 17 Mar 2002 14:44:42 -0000, "Ritchie Lawrence"
<rlaw...@commanddoline.co.uk> wrote:


>Hi Simon,
>If it's to do with NT batch, I'm always interested. By 'archive' do
>you mean Google, or is there some another place?
>

Yes I mean Google groups - though I guess other sites may be archiving
the newsgroup too

>Unless I've misunderstood you, I don't see whats tricky about getting a
>4 digit date, as you know its part of the 'date /t' output.

fair point - now I've actually tried your code - it does give a 4
digit year

>I also considered a solution like yours where the separator character
>(SC) is irrelevant, but decided against it as I felt it is more likely
>to fail had a user been 'playing around' with the SC.

>Reason being, anyone crazy enough to change the SC may just as well have
>decided to use more than one character, for example '--' or '~#~',
>causing any script that assumed a single SC to fail.
>
>Of course, '~#~' would cause my solution to fail as it stands (although
>'--' would be fine), but adding extra characters to my "delims" (omitted
>from my OP for clarity) is all that's required.

Well multiple character date separators is something I've yet to see
- but yes it would break the previous solution

>
>Taking these arguments to their extreme, one could append all non numeric
>characters to the "delims", keeping my solution a one-liner. On the other
>hand, a solution that catered for a 1, 2 or 3 character length separator
>would require additional coding.

The date formats for different country codes are as follows:

Country or language CountryCode Date format Time format
United States 001 01/23/1997 5:35:00.00p
Czechoslovakia 042 23.01.1997 17:35:00
France 033 23.01.1997 17:35:00 Germany
049 23.01.1997 17:35:00
Latin America 003 23/01/1997 5:35:00.00p
International English 061 23/01/1997 17:35:00.00
Portugal 351 23-01-1997 17:35:00 Finland
358 23.1.1997 17.35.00 Switzerland 041
23.01.97 17 35.00
Norway 047 23.01.97 17:35:00
Belgium 032 23/01/97 17:35:00
Brazil 055 23/01/97 17:35:00 Italy
039 23/01/97 17.35.00
United Kingdom 044 23/01/97 17:35:00.00
Denmark 045 23-01-97 17.35.00
Netherlands 031 23-01-97 17:35:00
Spain 034 3/12/98 17:35:00
Hungary 036 1997.01.23 17:35:00
Canadian-French 002 1997-01-23 17:35:00
Poland 048 1997-01-23 17:35:00 Sweden
046 1997-01-23 17.35.00

Now buried in that lot is finland with 23.1.1997

You might expect this to cause problems - but luckily the date command
ignores this particular format and displays 2 digits regardless.

This was the reason for parsing the DATE output based on character
position - unfortunately DATE isn't smart enough to ignore multiple
character date separators.


>
>All aspects considered, I maintain my earlier post stands as the
>preferred solution.
>

I'll go along with that - it's nice and short - I'd just change the
delims to "delims=\-/." so that all the 'standard' formats above are
covered.

Oh and this isn't going to work under Win95 or DOS - so change the
extension to .cmd to stop them from running it.

================== start getdate.cmd =========================
@echo off&setlocal

for /f "skip=1 tokens=3-6 delims=:.(\-/.)" %%a in ('echo.^|date') do (


for /f "tokens=2-4 delims=.\-/ " %%d in ('date /t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f
)
)

echo Month: [%mm%]
echo Date: [%dd%]
echo Year: [%yy%]

================== end getdate.cmd ===========================

Ritchie Lawrence

unread,
Mar 17, 2002, 5:13:42 PM3/17/02
to
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c94f516...@news.demon.co.uk...

> On Sun, 17 Mar 2002 14:44:42 -0000, "Ritchie Lawrence"
> <rlaw...@commanddoline.co.uk> wrote:
>
> Well multiple character date separators is something I've yet to see
> - but yes it would break the previous solution

I've also yet to see a non-standard seperator.

> >All aspects considered, I maintain my earlier post stands as the
> >preferred solution.
> >
> I'll go along with that - it's nice and short - I'd just change the
> delims to "delims=\-/." so that all the 'standard' formats above are
> covered.

It was covered, you've re-written my post with two periods.

> for /f "skip=1 tokens=3-6 delims=:.(\-/.)" %%a in ('echo.^|date') do (

--

Phil Robyn

unread,
Mar 18, 2002, 1:12:52 AM3/18/02
to
Jim Taylor wrote:
>
> On Thu, 14 Mar 2002 16:11:35 -0800, Phil Robyn
> <pro...@uclink.berkzipeley.edu> wrote:
>
> > Assuming that YOURVAR already contains "03/14/2002", you could do
> > the following:
> >
> > set YOURVAR=%YOURVAR:/=%
> > set YOURVAR=%YOURVAR:~4,4%%YOURVAR:~0,4%
>
> Interesting. After playing with it I see that the following single set
> command will do the same.
>
> set var=%var:~6,4%%var:~0,2%%var:~3,2%

Yes, you're absolutely right; the single command will yield the same
result. Nevertheless, the first command is also a nice one to know. :-)

>
> I understand how it works, with :~6,4 meaning use 4 characters beginning
> with an offset of 6, but I can't find any of it documented anywhere, not
> in Help|Reference|MS-DOS Commands anyway. Is it?

Type 'SET /?' (without the apostrophes) at the CMD prompt.

Garry Deane

unread,
Mar 18, 2002, 1:56:38 AM3/18/02
to
On Sat, 16 Mar 2002 12:47:20 -0000, "Ritchie"
<dontg...@enildnammoc.co.uk> wrote:

<snip>


>================== start getdate.bat =========================
>@echo off&setlocal
>
>for /f "skip=1 tokens=3-6 delims=:.(\-/)" %%a in ('echo.^|date') do (
> for /f "tokens=2-4 delims=.\-/ " %%d in ('date /t') do (
> set %%a=%%d&set %%b=%%e&set %%c=%%f
> )
>)
>
>echo Month: %mm%
>echo Date: %dd%
>echo Year: %yy%
>
>================== end getdate.bat ===========================
>

One word of caution - on XP, depending on the locale, "date/t" doesn't
always return the Day of the Week as the first token. It's necessary
to take an extra step and check whether the first token is numeric. If
it's not, then the date is in the second token.

@echo off
setlocal
for /f "tokens=1-2" %%a in ('date /t') do (
set date=%%a
set date1=%%b
)
if %date:~0,1% GTR 9 set date=%date1%

for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
for /f "tokens=1-3 delims=-/." %%d in ("%date%") do (
set %%a=%%d
set %%b=%%e


set %%c=%%f
)
)
echo Month: %mm%
echo Date: %dd%
echo Year: %yy%

Garry

Ritchie Lawrence

unread,
Mar 18, 2002, 5:14:02 PM3/18/02
to
"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3c958dcc...@192.168.0.2...

> One word of caution - on XP, depending on the locale, "date/t" doesn't
> always return the Day of the Week as the first token. It's necessary
> to take an extra step and check whether the first token is numeric. If
> it's not, then the date is in the second token.

Thanks for this info Gary. Can I ask you, in XP, when the DOW is not the
first token, it that because it is another token (presumably the last)
or because it does not appear at all?

And in this scenario, does the same happen with 'echo.^|date', and
what about %date%?

Simon Sheppard

unread,
Mar 18, 2002, 12:14:15 PM3/18/02
to
On Sun, 17 Mar 2002 22:13:42 -0000, "Ritchie Lawrence"
<rlaw...@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

unread,
Mar 16, 2002, 1:10:22 PM3/16/02
to
On Mon, 18 Mar 2002 06:56:38 GMT, Garry Deane
<garrydeane_at_yahoo.com.au> wrote:


>One word of caution - on XP, depending on the locale, "date/t" doesn't
>always return the Day of the Week as the first token. It's necessary
>to take an extra step and check whether the first token is numeric. If
>it's not, then the date is in the second token.
>
>@echo off
>setlocal
>for /f "tokens=1-2" %%a in ('date /t') do (
> set date=%%a
> set date1=%%b
>)
>if %date:~0,1% GTR 9 set date=%date1%
>

I don't have XP here to test it but I think this line will fail

if %date:~0,1% GTR 9 set date=%date1%

How can any single character evaluate to > 9 ?
If the first digit is text it will evaluate to 0

I'm tempted to suggest

if %date:~0,1% GTR 0 set...

but of course dates may have a leading zero, so 09 would evaluate to
the same as "Mon"

Ritchie Lawrence

unread,
Mar 18, 2002, 4:14:58 PM3/18/02
to
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c8a3e6...@news.demon.co.uk...

> On Sun, 17 Mar 2002 22:13:42 -0000, "Ritchie Lawrence"
> <rlaw...@commanddoline.co.uk> wrote:
>
> 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
>

Hi Simon,
This is really useful that you've posted ALL the date outputs. It
helps illustrate just whats involved trying to code a solution for
all NT o/s's. Nice use of the rarely used SHIFT command in you
solution.

I was playing earlier trying to do a SHIFT on the FOR variables -
no chance.

I actually believe the M$ cmd programmers monitor this group and
have a right laugh. If you're listening guys/gals why not put the
DOW between month and year in the next version?

--
Ritchie
Undo my address for email.

Ritchie Lawrence

unread,
Mar 18, 2002, 4:47:07 PM3/18/02
to
"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c93896c...@news.demon.co.uk...

>
> >if %date:~0,1% GTR 9 set date=%date1%
> >
>
> I don't have XP here to test it but I think this line will fail
>
> if %date:~0,1% GTR 9 set date=%date1%
>
> How can any single character evaluate to > 9 ?
> If the first digit is text it will evaluate to 0

Hi Guys,

If its not a digit, cmd does a string comparison. So it
does have the desired effect. I believe this behaviour is
undocumented and borders on being kinda quirky.

I always code these situations by surrounding the vars
with double quotes thereby 'guaranteeing' the desired
effect and enforcing it to the reader:-

if "%date:~0,1%" GTR "9" set date=%date1%

--

Alex K. Angelopoulos

unread,
Mar 18, 2002, 5:58:48 PM3/18/02
to
Just for completeness' sake, as a comparison on an XP system with "customized" date/time format I'm posting the date-time results from my system.

My system is set with the following date time format:
Date output yyyy-mm-dd
Time: HH:mm:ss (24-hr clock).

OUTPUT


C:\>ver
Microsoft Windows XP [Version 5.1.2600]
C:\>date /t

2002-03-18
C:\>echo.|date
The current date is: 2002-03-18
Enter the new date: (yy-mm-dd)
C:\>echo %DATE%
2002-03-18
C:\>time /t
17:56
C:\>echo.|time
The current time is: 17:56:50.79
Enter the new time:
C:\>echo %TIME%
17:57:01.23

"Ritchie Lawrence" <rlaw...@commanddoline.co.uk> wrote in message news:3c966...@mk-nntp-1.news.uk.worldonline.com...
: "Simon Sheppard" <si...@spam.invalid> wrote in message news:3c8a3e6...@news.demon.co.uk...

:
:

Simon Sheppard

unread,
Mar 16, 2002, 6:45:16 PM3/16/02
to
On Mon, 18 Mar 2002 21:47:07 -0000, "Ritchie Lawrence"
<rlaw...@commanddoline.co.uk> wrote:

>If its not a digit, cmd does a string comparison. So it
>does have the desired effect. I believe this behaviour is
>undocumented and borders on being kinda quirky.

OK I see what it's doing now - this is sort of documented under IF/?

"These comparisons are generic, in that if both string1 and
string2 are both comprised of all numeric digits, then the strings are
converted to numbers and a numeric comparison is performed."

P.S.
A follow on question from all this - how to display the day of week
under XP?

Garry Deane

unread,
Mar 18, 2002, 11:02:07 PM3/18/02
to
On Mon, 18 Mar 2002 22:14:02 -0000, "Ritchie Lawrence"
<rlaw...@commanddoline.co.uk> wrote:

>Thanks for this info Gary. Can I ask you, in XP, when the DOW is not the
>first token, it that because it is another token (presumably the last)
>or because it does not appear at all?
>
>And in this scenario, does the same happen with 'echo.^|date', and
>what about %date%?
>

Actually I don't have XP. The information was supplied by John Gray in
the UK who has done much testing of the various DATE/T, DATE, TIME/T,
TIME and NET TIME output formats for NT/W2k/XP for the myriad of
regional settings.

The bottom line for XP is that the DoW may or may not be present and
if present, may precede or follow the date fields. DATE and DATE/T
will in most, but not all cases, include/exclude the DoW identically
(i.e. if DoW is absent in DATE it will also be absent in DATE/T and
vice versa). If DoW is present, it will be in English in DATE/T but in
the local language in DATE. Nice and consistent huh!

Below is a summary file John produced showing some of the more unusual
formats. I also have the actual output from the date/time commands for
each regional setting if anyone wants a copy.

REGIONAL OPTIONS found in Windows XP Professional, UK English
=============================================================

The results from the commands DATE /T, DATE, TIME/T and TIME for
each of the 93 possible Regional Options differ SO much that it would
be very difficult to describe them. See my file DATETIME.FMT for
examples. Only the names of the Regional Options, Language codes, and
a brief comment are given, where needed.


Language/Country Lang Code

Africaans AFK TIME /T has nm (PM) but no AM
equivalent
Albanian SQI TIME /T has PD (AM) and MD (PM)
Azeri (Cyrillic) AZE
Azeri (Latin) AZE
Basque EUQ
Belarusian BEL
Bulgarian BGR DATE fields followed by two-char DoW
"?."?
Catalan CAT
Croatian HRV
Czech CSY
Danish DAN
Dutch (Belgium) NLB
Dutch (Netherlands) NLD
English (Australia) ENA DoW present in both DATE /T and DATE
English (Belize) ENL
English (Canada) ENC DoW absent in both DATE /T and DATE
English (Caribbean) ENB
English (Ireland) ENI DoW absent in both DATE /T and DATE
English (Jamaica) ENJ
English (New Zealand) ENZ DoW present in both DATE /T and DATE
English (Philippines) ENP
English (South Africa) ENS DoW absent in both DATE /T and DATE
English (Trinidad) ENT
English (United Kingdom) ENG DoW absent in both DATE /T and DATE
English (United States) ENU DoW present in both DATE /T and DATE
English (Zimbabwe) ENW
Estonian ETI
Faroese FOS
Finnish FIN
French (Belgium) FRB
French (Canada) FRC
French (France) FRA
French (Luxembourg) FRA
French (Monaco) FRM
French (Switzerland) FRS
FYRO Macedonian MKI
Galician GLC year value only two digits in DATEs
German (Austria) DEA
German (Germany) DEU
German (Liechtenstein) DEC
German (Luxembourg) DEL
German (Switzerland) DES
Greek ELL
Hungarian HUN yyyy.mm.dd. - note the final full
stop
Icelandic ISL
Indonesian IND
Italian (Italy) ITA
Italian (Switzerland) ITS
Kazakh KKZ
Krygyz (Cyrillic) KYR year value only two digits in DATEs
Latvian LVI yyyy.mm.dd. - note the final full
stop
Lithuanian LTH
Malay (Brunei Darussalam) MSB
Malay (Malaysia) MSL
Mongolian (Cyrillic) MON year value only two digits in DATEs
Norwegian (Bokmal) NOR
Norwegian (Nynorsk) NON
Polish PLK
Portuguese (Brazil) PTB
Portuguese (Portugal) PTG
Romanian ROM
Russian RUS
Serbian (Cyrillic) SRB
Serbian (Latin) SRL
Slovak SKY
Slovenian SLV
Spanish (Argentina) ESS
Spanish (Bolivia) ESB
Spanish (Chile) ESL
Spanish (Columbia) ESO
Spanish (Costa Rica) ESC
Spanish (Dominican Repub.) ESD
Spanish (Ecuador) ESF
Spanish (El Salvador) ESE
Spanish (Guatemala) ESG
Spanish (Honduras) ESH
Spanish (Mexico) ESM
Spanish (Nicaragua) ESI
Spanish (Panama) ESA
Spanish (Paraguay) ESZ
Spanish (Peru) ESR
Spanish (Puerto Rico) ESU
Spanish (Spain) ESP
Spanish (Uruguay) ESY
Spanish (Venezuela) ESV
Swahili SWK
Swedish SVE
Swedish (Finland) SVF
Tatar TTT
Turkish TRK
Ukrainian UKR
Uzbek (Cyrillic) UZB
Uzbek (Latin) UZB


Results from the command NET TIME /DOMAIN (or NET TIME
\\computername)

NET TIME /DOMAIN

Current time at \\ThePDC is m/d/yyyy h:mm xM example: 9/5/2000
5:04 AM
Local time (GMT) at \\ThePDC is m/d/yyyy h:mm xM example: 9/5/2000
11:22 PM
The command completed successfully.

Single letters m, d, or h mean that these values do NOT take leading
zeroes, and so can take 1 or 2 digits.

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


Garry Deane

unread,
Mar 19, 2002, 12:52:16 AM3/19/02
to
On Sat, 16 Mar 2002 23:45:16 GMT, si...@spam.invalid (Simon Sheppard)
wrote:

<Snip>


>P.S.
>A follow on question from all this - how to display the day of week
>under XP?
>-

If the day of week is absent e.g. English (United Kingdom), you have
to do a Day of the Week, Julian Day, Modified Julian Day or similar
calculation to determine the day number, calculate Day No mod 7 to get
the week day number then do a lookup to get the day name. The
following does it based on the Modified Julian Day Number. There are
other similar formulae around.

@echo off
setlocal
set dd=19
set mm=3
set yy=2002
:: Modified Julian Day 0 on 17 Nov, 1858 is a Wednesday
set Days=WedThuFriSatSunMonTue
set /a z=14-mm,z/=12
set /a jy=yy-z
set /a jm=12*z+mm-3
set /a mjd=153*jm+2,mjd/=5
set /a mjd=mjd+dd+365*jy+jy/4-jy/100+jy/400-678882
set /a "DoW=mjd%%7"
set /a DoW*=3
call set DoW=%%Days:~%DoW%,3%%
echo %DoW%

Garry

Ritchie Lawrence

unread,
Mar 19, 2002, 9:37:02 AM3/19/02
to
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
Undo my address for email.


"Simon Sheppard" <si...@spam.invalid> wrote in message news:3c8a3e6...@news.demon.co.uk...

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

unread,
Mar 19, 2002, 2:22:47 PM3/19/02
to
On Tue, 19 Mar 2002 04:02:07 GMT, Garry Deane
<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%]

Simon Sheppard

unread,
Mar 19, 2002, 2:25:58 PM3/19/02
to

nice bit of code - Thanks

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

Garry Deane

unread,
Mar 19, 2002, 7:01:51 PM3/19/02
to
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%]
>=================================================================

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.

>
>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.
>

I'll send a copy.

Garry

Ritchie Lawrence

unread,
Mar 21, 2002, 3:36:09 AM3/21/02
to
"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3c97d012...@192.168.0.2...

> 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%]
> >=================================================================
>
> 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.

Garry Deane

unread,
Mar 20, 2002, 4:30:11 AM3/20/02
to
On Thu, 21 Mar 2002 08:36:09 -0000, "Ritchie Lawrence"
<rlaw...@commanddoline.co.uk> wrote:

>"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message news:3c97d012...@192.168.0.2...
>> 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%]
>> >=================================================================
>>
>> 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.
>

I agree

Garry

0 new messages