How to extract Day of Week

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
swgivens
Posts: 2
Joined: 04 Mar 2009 09:24

How to extract Day of Week

#1 Post by swgivens » 04 Mar 2009 09:38

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]

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 19 Mar 2009 09:03


swgivens
Posts: 2
Joined: 04 Mar 2009 09:24

#3 Post by swgivens » 19 Mar 2009 10:01

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 19 Mar 2009 10:16

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

*SCRIPTER*
Posts: 18
Joined: 16 Mar 2009 08:18
Location: N/A
Contact:

#5 Post by *SCRIPTER* » 19 Mar 2009 15:37

---- :idea:

would
Posts: 1
Joined: 20 Mar 2009 02:14

#6 Post by would » 20 Mar 2009 04:07

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

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#7 Post by DosItHelp » 22 Mar 2009 23:13

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:

Post Reply