DATE
suggest changeDisplays or sets the date. The way the date is displayed depends on country settings. Date can also be displayed using echo %DATE%
.
Examples
$ date /t
Wed, 03/13/2019
$ echo %DATE%
Wed, 03/13/2019
Getting date in the ISO format, like 2000-01-28
is hard because the date format depends on country settings.
- If you can assume the format of
Mon 01/28/2000
, the following will do:set isodate=%date:~10,4%-%date:~4,2%-%date:~7,2%
- If you have WMIC, the following is locale independent:
for /f %i in ('wmic os get LocalDateTime') do @if %i lss a if %i gtr 0 set localdt=%iset isodate=%localdt:~0,4%-%localdt:~4,2%-%localdt:~6,2%
- To use the above in a batch, turn %i into %%i and remove @ from before if.
- If you have Perl installed:
for /f %i in ('perl -MPOSIX -le "print strftime '%Y-%m-%d', localtime"') do @set isodate=%i
Links:
- date at ss64.com
- date at Microsoft
- How to get current datetime on Windows command line, in a suitable format for using in a filename? at stackoverflow
$ date /?
Displays or sets the date.
DATE [/T | date]
Type DATE without parameters to display the current date setting and
a prompt for a new one. Press ENTER to keep the same date.
If Command Extensions are enabled the DATE command supports
the /T switch which tells the command to just output the
current date, without prompting for a new date.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents