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?

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

1
c:\> WMIC Path Win32_LocalTime Get

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.