Page 1 of 1

How to extract Day of Week

Posted: 04 Mar 2009 09:38
by swgivens
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]

Posted: 19 Mar 2009 09:03
by avery_larry

Posted: 19 Mar 2009 10:01
by swgivens
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

Posted: 19 Mar 2009 10:16
by avery_larry
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

Posted: 19 Mar 2009 15:37
by *SCRIPTER*
---- :idea:

Posted: 20 Mar 2009 04:07
by would
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

Posted: 22 Mar 2009 23:13
by DosItHelp
Alternatively use Julian days modulo seven to look up a string like this:

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? :wink: