This seems to be a recurring question on a lot of forums:
How to get the current date as yyyyMMdd into environment variable datestring in a regional independent way?
A lot of solutions are using construct around the %date% environment variable similar to this:
for /f "usebackq tokens=1,2,3,4 delims=- " %%i in (`echo %date%`) do ( set datestring=%%l%%k%%j echo %%i echo %%j echo %%k echo %%l ) echo %datestring%
There are two things wrong with this kind of solution:
- It depends on the order of fields inside the %date% environment variable
- It depends on the delimiter inside the %date% environment variable (specified by delims in the above example)
(note: the %date% environment variable has the same format as the date command).
For sytems having Powershell installed, this is a possible solution: Read the rest of this entry »