ammounpierre
asked on
Getting Day of Week from DOS ?
Hello Gurus,
I am running a script to backup files using robocopy.
my batch file uses date /t to get the 3 letters for the date.
now my problem is that depending on the settings in the regional settings in the control panel...
date /t does not give me Fri for example but rather 29 or 05 ....
and I do not want to change the settings... (there are many laptops to backup and each has a separate settings...)
So is there a way to get the 3 letters for the DOW from dos ?
thanks.
I am running a script to backup files using robocopy.
my batch file uses date /t to get the 3 letters for the date.
now my problem is that depending on the settings in the regional settings in the control panel...
date /t does not give me Fri for example but rather 29 or 05 ....
and I do not want to change the settings... (there are many laptops to backup and each has a separate settings...)
So is there a way to get the 3 letters for the DOW from dos ?
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this. Put in a batch file and run it at the command line.
Then try at the command line
set dow
and see what it reports back. I think it might be universal in operation. It is code I picked up from the 'Net when having to do some date stuff.
Then try at the command line
set dow
and see what it reports back. I think it might be universal in operation. It is code I picked up from the 'Net when having to do some date stuff.
echo. | date | FIND "(mm" > NUL
IF errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
GOTO :EOF
:Parsedate
FOR /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
set %1=%%A&set %2=%%B&set YYYY=%%C
) else (
set DOW=%%A&set %1=%%B&set %2=%%C&set YYYY=%%D)
Set DateStamp=%YYYY%%MM%%DD%
echo DateStamp: %DateStamp% ( day of the week: %DOW% )
echo.
dbrunton,
this does not work for the DOW, as it is not always contained in date output. If the DOW is in date /t, it is trivial, else comes the difficult part.
this does not work for the DOW, as it is not always contained in date output. If the DOW is in date /t, it is trivial, else comes the difficult part.
As Qlemo pointed out, date information manipulation using plain shell-scripting code is often not trivial, particularly with different locales that use different output formats for the built-in commands. That's why I wrote the datex utility -- I have found it greatly simplifies shell script code when this kind of functionality is needed. Bill.
Open in new window