Date format in cmd?

Toshiba / P30
December 3, 2010 at 11:29:14
Specs: Windows Vista, 3.2/512MB
Okay I was asked to move my question to this forum.

I want to create a directory with the current date and time which I have done with the following bat file;

c:
cd \
if not exist cimsbkup mkdir cimsbkup
cd \cimsbkup
mkdir %DATE:~2,2%%DATE:~5,2%%DATE:~8,2%-%TIME:~0,2%%TIME:~3,2%
cd %DATE:~2,2%%DATE:~5,2%%DATE:~8,2%-%TIME:~0,2%%TIME:~3,2%

However I have seen a machine that displays the date in DAY YYYY-MM-DD format, I looked at regional settings and it does not seem to be coming from there as there is not even an option to add the DAY to the DATE, I only get DATE Formats. Does anyone know how the date command gets formatted in cmd?


See More: Date format in cmd?

Report •


#1
December 3, 2010 at 11:54:03
Observational data on a en-us WinXP box: If the short date format is some variant of Month/day/year, you'll get the abbreviated day prefix. The important thing is the order. First month, then day, then year. If the order's different, nothing will be prefixed.

How To Ask Questions The Smart Way


Report •

#2
December 3, 2010 at 12:03:52
The DATE command obtains the format for the day, month and year from the Regional and Language options. I have checked this experimentally. The system makes these settings available to applications so they can format dates according to user preferences. But some applications ignore these settings and format dates any way they wish.

There is a great deal more to these regional settings than are made available in Control Panel. Many are defined by the locale in use and cannot be easily changed by the user. But all are available to applications if they wish to use them. That includes how the day of the week will be displayed.


Report •

#3
December 3, 2010 at 19:34:48
@echo off > d.d & setLocal enableDELAYedeXpansion

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9                                                                  ) do if errorlevel %%a set DD=0%%a
for %%a in (                  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set DD=%%a
set D=%errorlevel%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday

month
for %%a in (1 2 3 4 5 6 7 8 9         ) do if errorlevel %%a set MM=0%%a
for %%a in (                  10 11 12) do if errorlevel %%a set MM=%%a

if %MM%==01 set Mon=Jan
if %MM%==02 set Mon=Feb
if %MM%==03 set Mon=Mar
if %MM%==04 set Mon=Apr
if %MM%==05 set Mon=May
if %MM%==06 set Mon=Jun
if %MM%==07 set Mon=Jul
if %MM%==08 set Mon=Aug
if %MM%==09 set Mon=Sep
if %MM%==10 set Mon=Oct
if %MM%==11 set Mon=Nov
if %MM%==12 set Mon=Dec

year
if errorlevel 215 set YYYY=2007
if errorlevel 216 set YYYY=2008
if errorlevel 217 set YYYY=2009
if errorlevel 218 set YYYY=2010
if errorlevel 219 set YYYY=2011
if errorlevel 220 set YYYY=2012

set   YYYYMMDD=%YYYY%%MM%%DD%
if not exist %YYYYMMDD% md %YYYYMMDD%

del day.com
del month.com
del year.com
del dat.com


=====================================
Life is too important to be taken seriously.

M2


Report •
Related Solutions


Ask Question