Seems like the environment date - %date% is user profile dependant.
If I run echo %date% using my account - I get 16/09/2009
If I run echo %date% using a service account - I get Wed 16/09/2009
Workaround is to strip the dayofweek from the above dates and then split each day, month and year component from the and reassemble each component manually.
For /F "tokens=1-4 delims=/ " %%i in ('date /t') Do (
Set _1=%%i
Set _2=%%j
Set _3=%%k
Set _4=%%l
)
:: Assign to datestamp and split out each date component to associated variable
:: Check for case when date stamp doesn't include day of week
If (%_4%)==() (
Set _datestamp=%_3%%_2%%_1%
Set _year=%_3%
Set _month=%_2%
Set _day=%_1%
) else (
Set _datestamp=%_4%%_3%%_2%
Set _year=%_4%
Set _month=%_3%
Set _day=%_2%
)
For /F "tokens=1-4 delims=/ " %%i in ('date /t') Do (
Set _1=%%i
Set _2=%%j
Set _3=%%k
Set _4=%%l
)
:: Assign to datestamp and split out each date component to associated variable
:: Check for case when date stamp doesn't include day of week
If (%_4%)==() (
Set _datestamp=%_3%%_2%%_1%
Set _year=%_3%
Set _month=%_2%
Set _day=%_1%
) else (
Set _datestamp=%_4%%_3%%_2%
Set _year=%_4%
Set _month=%_3%
Set _day=%_2%
)
No comments:
Post a Comment