1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

DATE /T

Discussion in 'Support' started by JohnQSmith, May 24, 2012.

  1. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    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?
     
  2. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    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
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,075
    Likes Received:
    30
    I see a different difference. :-)

    Code:
    TCC:
    v:\> date /t
    Thu 2012-05-24
     
    CMD:
    C:\Users\vefatica> date /t
    2012-05-24
     
  4. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Hmm... gonna hafta look at my localization settings although I think a specific machine's output should be the same.
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,036
    Likes Received:
    84
    Yes. Because TCC is emulating 4DOS's behavior, which had the option before CMD.

    It could probably be changed now that most user's don't expect backwards compatibility with 4DOS.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,036
    Likes Received:
    84
    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.
     
  7. TMac

    Joined:
    Nov 11, 2017
    Messages:
    2
    Likes Received:
    0
    And five years later this STILL isn't fixed.

    How can I get the correct format when under TCC?
     
  8. rps

    rps

    Joined:
    Jul 6, 2008
    Messages:
    232
    Likes Received:
    3
    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.
     
  9. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    698
    Likes Received:
    8
    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
     
  10. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    698
    Likes Received:
    8
    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
     
  11. TMac

    Joined:
    Nov 11, 2017
    Messages:
    2
    Likes Received:
    0
    @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. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    698
    Likes Received:
    8


    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
     
  13. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,358
    Likes Received:
    39
    I think you want @EXECSTR, not @EXEC.
     
  14. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    698
    Likes Received:
    8
    ...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
     

Share This Page