|
Answer» How can I change the current date format from DD/MM/YYYY to YYYY-MM-DD? Note: it is "-", not "/" to connect the figures.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.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. 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 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".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-) 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
QuotePut 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.
QuotePresumably 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 . Thanks, Sidewinder.Hi, uli_glueck and Sidewinder, thanks for your contributions to this TOPIC. The code provided DOES work! Now I have an idea on how to deal with the date string.
|