I tried doing searches on google; but all the link I found were based on the current date; which is really easy. I also found an old post on here pointing to a chinese site. Anyway...
I'm trying to figure out a way to get the day of week based on a date with the format: xx/xx/xxxx
So, if %date%=04/27/2012, it will set day=Fri
Whatever the solution, ideally, it should work under Vista, 7, Win2K3, Win2K8
I found an executable that does this; however, I would much prefer to do it without an extra executable.
Thanks as always!
day of week calculation of any date
Moderator: DosItHelp
Re: day of week calculation of any date
Code: Select all
@ECHO OFF
REM GET MONTH, DAY, YEAR VALUES
FOR /F "TOKENS=1-3 DELIMS=/" %%A IN ("%1") DO SET MM=%%A& SET DD=%%B& SET YY=%%C
REM ELIMINATE LEFT ZEROS
SET /A DD=10%DD% %% 100, MM=10%MM% %% 100
REM CALCULATE JULIAN DAY NUMBER AND DAY OF WEEK
IF %MM% LSS 3 SET /A MM+=12, YY-=1
SET /A A=YY/100, B=A/4, C=2-A+B, E=36525*(YY+4716)/100, F=306*(MM+1)/10, JDN=C+DD+E+F-1523, DOW=JDN %% 7 + 1
ECHO Number of day of week: %DOW%
REM CONVERT DOW NUMBER TO DOW NAME
FOR /F "TOKENS=%DOW%" %%D IN ("Sun Mon Tue Wed Thu Fri Sat") DO ECHO Day of week: %%D
Re: day of week calculation of any date
That worked perfectly! Thanks so much!