3

Is it possible to specify date format (maybe as paramater or some similar way) which batch command date returns or it only depends on windows regional settings? What I would like is to somehow specify date format when i call date so that the batch script can extract day, month and year and save them in variables. The problem is that some machines return dd/MM/yyyy and some MM/dd/yyyy so in one case day and month would be switched. Some also use dots as separators. Can I somehow tell date to return for example MM/dd/yyyy so I can differentiate which is day and which is month?

ValentQ
  • 53
  • 5

3 Answers3

1

I am not sure if these will definitely resolve your issue, but please take a look at Date and Time functions on link http://commandline.co.uk/lib/treeview/index.php.

Parag Doke
  • 863
  • 7
  • 17
1
c:\> WMIC Path Win32_LocalTime Get
npocmaka
  • 55,367
  • 18
  • 148
  • 187
0

The command

for /f %%a in ('wmic path win32_localtime get /format:list ^| findstr "="') do (set %%a)

Creates the following environment variables:

Day, DayOfWeek, Hour, Milliseconds, Minute, Month, Quarter, Second, WeekInMonth, Year

Which can be accessed as usual: %Year%

To see the values use wmic path win32_localtime

note: The values can be blank. On my desktop, Milliseconds has no value.

note 2: If you use this in the command line, replace %% with %

Inspiration for this answer Setting a windows batch file variable to the day of the week

Community
  • 1
  • 1
dconman
  • 90
  • 3