I suppose I'm missing something really obvious, but I can't find much on date formats. I need to determine the day of the week from %DATE% and set a variable to format such as MONDAY, TUESDAY, etc. Note that I also need the day in caps.
Thx[/quote]
How to extract Day of Week
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Thanks for the info. Much more elaborate than the simple approach I ended up taking:
set day=%DATE:~0,3%
IF %day% == Mon set dayofweek=Monday
IF %day% == Tue set dayofweek=Tuesday
IF %day% == Wed set dayofweek=Wednesday
IF %day% == Thu set dayofweek=Thursday
IF %day% == Fri set dayofweek=Friday
IF %day% == Sat set dayofweek=Saturday
set day=%DATE:~0,3%
IF %day% == Mon set dayofweek=Monday
IF %day% == Tue set dayofweek=Tuesday
IF %day% == Wed set dayofweek=Wednesday
IF %day% == Thu set dayofweek=Thursday
IF %day% == Fri set dayofweek=Friday
IF %day% == Sat set dayofweek=Saturday
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
swgivens wrote:Thanks for the info. Much more elaborate than the simple approach I ended up taking:
set day=%DATE:~0,3%
IF %day% == Mon set dayofweek=Monday
IF %day% == Tue set dayofweek=Tuesday
IF %day% == Wed set dayofweek=Wednesday
IF %day% == Thu set dayofweek=Thursday
IF %day% == Fri set dayofweek=Friday
IF %day% == Sat set dayofweek=Saturday
Just remember -- not all OS version actaully include the DAY in the %date% variable
avery_larry wrote:swgivens wrote:Thanks for the info. Much more elaborate than the simple approach I ended up taking:
set day=%DATE:~0,3%
IF %day% == Mon set dayofweek=Monday
IF %day% == Tue set dayofweek=Tuesday
IF %day% == Wed set dayofweek=Wednesday
IF %day% == Thu set dayofweek=Thursday
IF %day% == Fri set dayofweek=Friday
IF %day% == Sat set dayofweek=Saturday
Just remember -- not all OS version actaully include the DAY in the %date% variable
it also useful for me
thanks
Alternatively use Julian days modulo seven to look up a string like this:
http://www.dostips.com/DtCodeCmdLib.php#jdate
DosItHelp?
Code: Select all
@Echo Off
call:jdate JD
set /a d=1+(JD%%7)
for /f "tokens=%d%" %%A in ("MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY") do echo.%%A
GOTO:EOF
::-----------------------------------------------------------------------------------
::-- Functions start below here
::-----------------------------------------------------------------------------------
:jdate JD DateStr -- converts a date string to Julian day number with respect to regional date format
>> copy from http://www.dostips.com/DtCodeCmdLib.php#jdate
http://www.dostips.com/DtCodeCmdLib.php#jdate
DosItHelp?