%date%

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If you type %DATE% in Windows 2000 (after modifying your regional options)
you always get the first part of the Day.. like "Thur".. it appears that it
is using the long date format.... whereas when you modify the date format in
XP and type %DATE% you get 10-28-2004 (correct)... where is the modification
to get 2000 to format dates in dos like that?
 
Maximus said:
If you type %DATE% in Windows 2000 (after modifying your regional options)
you always get the first part of the Day.. like "Thur".. it appears that it
is using the long date format.... whereas when you modify the date format in
XP and type %DATE% you get 10-28-2004 (correct)... where is the modification
to get 2000 to format dates in dos like that?

Your post is a little unclear. When I type
echo %date%
in WinXP then I get "Thu 10-28-2004". I don't get a blank as you
suggest. In Win2000 I also get "Thu 10-28-2004, and not
"Thur 10-20-2004" as you write.

What exactly do you mean with "get 2000 to format dates in dos"?
Do you mean Windows 2000, or do you mean DOS? Which
version of DOS?

If you require a an output that is independent of the operating
system and of the regional settings then you could use this
batch file under WinNT/2000/XP:

@echo off
for /F "tokens=1-5" %%a in ('now.exe') do echo %%a %%c %%b %%e

It generates this output: Mon 15 Nov 2004. Now.exe comes with the
Win2000 Resource Kit.
 
Pegasus (MVP) said:
Your post is a little unclear. When I type
echo %date%
in WinXP then I get "Thu 10-28-2004". I don't get a blank as you
suggest. In Win2000 I also get "Thu 10-28-2004, and not
"Thur 10-20-2004" as you write.

What exactly do you mean with "get 2000 to format dates in dos"?
Do you mean Windows 2000, or do you mean DOS? Which
version of DOS?

If you require a an output that is independent of the operating
system and of the regional settings then you could use this
batch file under WinNT/2000/XP:

@echo off
for /F "tokens=1-5" %%a in ('now.exe') do echo %%a %%c %%b %%e

It generates this output: Mon 15 Nov 2004. Now.exe comes with the
Win2000 Resource Kit.
Sorry, the thing I am doing is that I am running Printmig from a w2k
workstation. I assume you know that program.
I made this batfile with this line: printmig -b
\\servername\Backup\%date%.cab \\servername. It will generate a cabfile.
When I was running it from a XP workstation the output file was namned
2004-11-08.cab
From a w2k workstation the file get a different name Thu.cab.
So when I type date in cmd.exe I get 2004-11-08 in XP and in a w2k
workstation I get Thu 2004-11-08. So basically the %date% in w2k grabs the
thu instead of the date itself. I hope you understand this time.
Thank you.

Regards
Henrik
 
Maximus said:
Sorry, the thing I am doing is that I am running Printmig from a w2k
workstation. I assume you know that program.
I made this batfile with this line: printmig -b
\\servername\Backup\%date%.cab \\servername. It will generate a cabfile.
When I was running it from a XP workstation the output file was namned
2004-11-08.cab
From a w2k workstation the file get a different name Thu.cab.
So when I type date in cmd.exe I get 2004-11-08 in XP and in a w2k
workstation I get Thu 2004-11-08. So basically the %date% in w2k grabs the
thu instead of the date itself. I hope you understand this time.
Thank you.

Regards
Henrik

I am not familiar with printmig.

The default value for %date% is dow dd/mm/yy. The order of the
date components can vary, as can the the separator. It could be
a slash, a dash or some other character. The slash would cause
some obvious problems in your batch file.

If you want a really robust batch file that is independent of any
regional settings then you should use something along these
lines:

1 @echo off
2 for /F "tokens=1-5" %%a in ('now.exe') do set MyDate=%%a-%%c-%%b-%%e
3 printmig -b \\servername\Backup\%MyDate%.cab \\servername

For a band-aid solution you could do this:
1 @echo off
2 set MyDate=%date%
3 ver | find /i "Windows 2000" && for /F "tokens=2" %%a in ('echo %date%')
do set MyDate=%date%
4 printmig -b \\servername\Backup\%MyDate%.cab \\servername

The second solution will fail on machines that have different
regional data format settings.

now.exe is included with the Win2000 Resource Kit. I'm sure you
can download freeware versions from the net.

Line numbers are for clarity only. Remove them before running
the batch file.
 
If you type %DATE% in Windows 2000 (after modifying your regional options)
you always get the first part of the Day.. like "Thur".. it appears that it
is using the long date format.... whereas when you modify the date format in
XP and type %DATE% you get 10-28-2004 (correct)... where is the modification
to get 2000 to format dates in dos like that?


Use Univdate, tip 4835 in the 'Tips & Tricks' at http://www.jsiinc.com
to return the MM DD and YY environment variables in any NT-based
O/S.


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Pegasus (MVP) said:
I am not familiar with printmig.

The default value for %date% is dow dd/mm/yy. The order of the
date components can vary, as can the the separator. It could be
a slash, a dash or some other character. The slash would cause
some obvious problems in your batch file.

If you want a really robust batch file that is independent of any
regional settings then you should use something along these
lines:

1 @echo off
2 for /F "tokens=1-5" %%a in ('now.exe') do set MyDate=%%a-%%c-%%b-%%e
3 printmig -b \\servername\Backup\%MyDate%.cab \\servername

For a band-aid solution you could do this:
1 @echo off
2 set MyDate=%date%
3 ver | find /i "Windows 2000" && for /F "tokens=2" %%a in ('echo %date%')
do set MyDate=%date%
4 printmig -b \\servername\Backup\%MyDate%.cab \\servername

The second solution will fail on machines that have different
regional data format settings.

now.exe is included with the Win2000 Resource Kit. I'm sure you
can download freeware versions from the net.

Line numbers are for clarity only. Remove them before running
the batch file.
Thank you, you are a champ!
Regards
Henrik
 
Jerold Schulman said:
Use Univdate, tip 4835 in the 'Tips & Tricks' at http://www.jsiinc.com
to return the MM DD and YY environment variables in any NT-based
O/S.


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com

As far as I can see, univdate.bat deals with the DOW and delimiter issue
but it still returns the date elements in an order that is dependent on the
regional settings. It would be nice if Microsoft gave us an inbuilt
command or variable that returns the date and time in a standardised
way, completely independent of any regional setting - a move that is
long overdue!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top