DATE /T

Jan 19, 2011
581
10
Norman, OK
#1
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?
 
Jan 19, 2011
581
10
Norman, OK
#2
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
 

rconn

Administrator
Staff member
May 14, 2008
10,576
97
#6
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.
 

rps

Jul 6, 2008
300
4
#8
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.
 
Nov 11, 2017
4
0
#11
@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?
 
#12


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