Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: change date display format in DOS  (Read 22585 times)

0 Members and 1 Guest are viewing this topic.

nnf2540

  • Guest
change date display format in DOS
« on: September 10, 2006, 10:22:28 PM »
How can I change the current date format from DD/MM/YYYY to YYYY-MM-DD?
Note: it is "-", not "/" to connect the figures.

Fed

  • Moderator


  • Sage
  • Thanked: 35
    • Experience: Experienced
    • OS: Windows XP
    Re: change date display format in DOS
    « Reply #1 on: September 11, 2006, 01:22:03 AM »
    Assuming you're not talking about real dos then you can change it in Windows Control Panel Regional Settings and your 'dos prompt' will reflect the changes.

    nnf2540

    • Guest
    Re: change date display format in DOS
    « Reply #2 on: September 11, 2006, 01:09:40 PM »
    What I really want is to get a DATE string in the format of YYYY-MM-DD, and this YYYY-MM-DD string can be redirected to and stored as a text file. Is it possible to change the format with a dos command? Or this task requires a batch file to complete? Thanks. :D

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: change date display format in DOS
    « Reply #3 on: September 11, 2006, 02:32:45 PM »
    There is no command that came with your OS (whatever it might be) but on some systems you can build one yourself:

    Code: [Select]
    for /f "tokens=2-4 delims=/ " %i in ('date /t') do echo %k-%i-%j > date.txt

    Note: Example will work at command line; if used in batch file double up on all the % symbols

     8-)

    This must be week FOR ;D
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    nnf2540

    • Guest
    Re: change date display format in DOS
    « Reply #4 on: September 12, 2006, 04:14:03 AM »
    Hi, thanks a lot, Sidewinder! I do get a date string "2006-09-12" with a revised version of your command:
    FOR /F "TOKENS=1-3 DELIMS=/ " %I IN ('DATE /T') DO ECHO %K-%J-%I > DATE.TXT

    Now I want to create a folder using the date string as the folder name, since the name rule is 8.3 format, so I need to use 8 digits for the name, better use "06-09-12", how can I chop off "20" in the head of string?

    I have tried to use delims=/0, but not successful, it will appear "6-9-12".

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: change date display format in DOS
    « Reply #5 on: September 12, 2006, 06:24:21 AM »
    Presumably your OS is a state  secret. Try using the KISS method, drop the hyphens:

    Code: [Select]
    FOR /F "TOKENS=1-3 DELIMS=/ " %I IN ('DATE /T') DO ECHO %K%J%I > DATE.TXT

    Quote
    ...since the name rule is 8.3 format
    Why?

     8-)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    uli_glueck

    • Guest
    Re: change date display format in DOS
    « Reply #6 on: September 12, 2006, 07:04:44 AM »

    Put the date in a variable and substitute it:
    :: --------
    FOR /F "TOKENS=1-3 DELIMS=/ " %I IN ('DATE /T') DO set datum=%K-%J-%I
    set datum=%datum:~2%
    :: ------

    Should give you 06-09-12

    hope it helps
    uli

    nnf2540

    • Guest
    Re: change date display format in DOS
    « Reply #7 on: September 12, 2006, 01:14:33 PM »
    Quote
    Put the date in a variable and substitute it:
    :: --------
    FOR /F "TOKENS=1-3 DELIMS=/ " %I IN ('DATE /T') DO set datum=%K-%J-%I
    set datum=%datum:~2%
    :: ------

    Should give you 06-09-12

    hope it helps
    uli



    It DOES work! Thanks a lot. ;D

    nnf2540

    • Guest
    Re: change date display format in DOS
    « Reply #8 on: September 12, 2006, 01:20:35 PM »
    Quote
    Presumably your OS is a state  secret. Try using the KISS method, drop the hyphens:

    Code: [Select]
    FOR /F "TOKENS=1-3 DELIMS=/ " %I IN ('DATE /T') DO ECHO %K%J%I > DATE.TXT

    Quote
    ...since the name rule is 8.3 format
    Why?

     8-)


    hehehe,,,,,,,This is my own rule.  ;) Because all my other files and folders are stored in this 8.3 format, and I don't want an exception, just to keep them look nice and neat :D. Thanks, Sidewinder.

    nnf2540

    • Guest
    Re: change date display format in DOS
    « Reply #9 on: September 12, 2006, 03:21:54 PM »
    Hi, uli_glueck and Sidewinder, thanks for your contributions to this topic. The code provided DOES work!  ;D Now I have an idea on how to deal with the date string.