Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

DATE /T

Jan
616
15
I have a BATCH file that in CMD parses the DATE /T command to create some variables which are used to create directories.
Code:
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
set temp_today=%%b
set temp_fulldate=%%c%%a%%b
)
I checked the directory where the new directories are created and noticed that today's directory was missing. I then realized that I had run the batch in TCC instead of CMD. I found the new directory, but it was not named what it should have been. Come to find out, the DATE command in CMD creates different output than the DATE command in TCC.
Code:
cmd> date /t
Thu 05/24/2012
Code:
tcc> date /t
Thu  5/24/2012
Is this intentional? If so, why when compatibility with CMD is usually paramount?
 
I found another DATE output discrepancy; this time with the built in variable. The first command of each example just shows that the variable is not previously set.
Code:
cmd> set date
Environment variable date not defined
 
cmd> echo %date%
Thu 05/24/2012
Code:
tcc> set date
TCC: Not in environment "date*"
 
tcc> echo %date
5/24/2012
 
I see a different difference. :-)

Code:
TCC:
v:\> date /t
Thu 2012-05-24
 
CMD:
C:\Users\vefatica> date /t
2012-05-24
 
I see a different difference. :)
Hmm... gonna hafta look at my localization settings although I think a specific machine's output should be the same.
 
I found another DATE output discrepancy; this time with the built in variable.

The TCC output is consistent across machines; the CMD output will vary (wildly). IMHO when creating batch files it's more important to have widespread consistency instead of CMD's random variable output.

But the %DATE% variable is about the worst one you could use for anything requiring consistency.
 
And five years later this STILL isn't fixed.

How can I get the correct format when under TCC?
Have you tried?
Code:
v21.01.58
$date /f2 /t
Sat 11/11/2017
In Windows 10
Code:
C:\Users\rps>echo %date%
Sat 11/11/2017
Works even in v17
Code:
v17.00.77
$date /f2 /t
Sat 11/11/2017
Maybe I lost the OPs' objective, but it seems there is a method to get a CMD version of date from TCC and it works back to TCC v17.00.77.
 
For those that may not be aware, if you want to use the CMD version of DATE in TCC, disable the internal TCC DATE command;
Code:
setdos /i-date

For more info on the CMD DATE, visit https://ss64.com/nt/date.html

Joe
 
Hmmm....

As I have Cygwin on my system, when I disable the internal TCC DATE command, I am then using the BASH Date command.

Not a bad thing, really, much more powerful than the CMD Date.

For more info on the BASH Date command, visit https://ss64.com/bash/date.html

Joe
 
@rps, not so good for cmd files. I wound up branching... if [%TCMD%]==[] goto DOS
and handling them separately.

Joe, great tip. Needs better search indexing. But I'm not convinced. From a TCC prompt...

[]date
Sat 11/11/2017 17:27:58
New date (mm-dd-[yy]yy):

[]echo %date%
11/11/2017

Do you see an inconsistency here?
 


Interesting.

When I run this under CMD 64-bit and CMD 32-bit, I get;
Code:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\utils>echo %date%
Sat 11/11/2017

When I disable internal TCC Date, I get the same thing that you did;
Code:
c:\users\jlc\utils>ver /r & which date & echo %date%

TCC  18.00.32 x64   Windows 7 [Version 6.1.7601]
TCC Build 32   Windows 7 Build 7601  Service Pack 1
Registered to Joe Caverly - 1 System License
date is an unknown command
11/11/2017

So, Rex's posts in #5 and #6 above, must be the reason.

What about this alias?
Code:
alias date=cmd /c date %$

...and/or
Code:
set date=`%@exec[cmd /c date /t]`

...which returns
Code:
echo %date%
Sat 11/11/2017
0

...and how do I get rid of that 0?

Joe
 
...and that is what happens when I'm too tired.

Thankyou, Charles.
Code:
c:\users\jlc\utils>set date=`%@execstr[cmd /c date /t]`

c:\users\jlc\utils>set date
%@execstr[cmd /c date /t]

c:\users\jlc\utils>echo %date%
Sun 11/12/2017

c:\users\jlc\utils>

Joe
 

Similar threads

Back
Top