JSI Tip 7047. How do I convert a date to the day number and day name?

Jerold Schulman

August 10, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted Day.bat to calculate the day number and day name.

The syntax for using Day.bat is:

call day yyyy mm dd daynumb daytext

where yyyy is the 4 digit year, mm is a 2 digit month, and dd is a 2 digit day of the month. Daynumb is a call directed environment variable that will contain the day number, where Monday is 1 and Sunday is 7. Daytext is a call directed environment variable that will contain the day name (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday).

NOTE: This script was modified on 24-Aug-2003 to fix a century problem.

Daybat contains:

@echo offif {%5}=={} @echo Syntax: Call day yyyy mm dd daynumb daytext&goto :EOFsetlocalset montabl=0033614625035set monleap=0623614625035set daytab=7Sunday###1Monday###2Tuesday##3Wednesday4Thursday#5Friday###6Saturday#set /a century=1set /a century4=1set /a yyyy=%1set /a mm=100%2%%100set /a dd=100%3%%100set /a leap=%yyyy%%%4if %leap% EQU 0  set /a century=%yyyy%%%100if %century% EQU 0 set /a century4=%yyyy%%%400if %leap% EQU 0 set montabl=%monleap%set /a day=%yyyy% + (%yyyy% / 4)set /a day=%day% - (%yyyy% / 100)set /a day=%day% + (%yyyy% / 400)set /a day=%day% + %dd%call set /a mon=%%montabl:~%mm%^,1%%set /a day=%day% + %mon% - 1set /a day=%day%%%7set /a day=%day% * 10if %century% EQU 0 if %century4% NEQ 0 if %mm% LSS 3 set daytab=1Monday###2Tuesday##3Wednesday4Thursday#5Friday###6Saturday#7Sunday###call set w5=%%daytab:~%day%^,10%%set /a daynumb=%w5:~0,1%set daytext=%w5:~1,9%set daytext=%daytext:#=%endlocal&set %4=%daynumb%&set %5=%daytext%

NOTE: See What is the ISO week number and day for a given date?



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like