Question : Week Number in DOS

How do I find out the current week number of the year in DOS?

example: today is week = 25

Answer : Week Number in DOS

Here's a slightly different version.  The prior version I posted calculates the week number purely as the number of weeks (7 days) since January 1.  So January 1 to January 7 is always week 1, etc.

The version attached to this post does it a little different.  The assumption here is that weeks always start on Monday.  So if January 1 was on a Saturday, then Saturday and Sunday (January 1 and 2) would be week 1, but then January 3 (Monday) would show as week 2.

Hope this helps.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
@echo off 
REM Set needed options
setlocal ENABLEEXTENSIONS
setlocal ENABLEDELAYEDEXPANSION 
REM Extract date components from current date
set /a MM=%DATE:~4,2%
set /a DD=%DATE:~7,2%
set /a YYYY=%DATE:~10,4%
set YY=%DATE:~12,4% 
REM Get Weeknumber
call :WeekNumber %MM% %DD% %YYYY%
echo %Week%
goto :EOF 
:WeekNumber
REM Calculate an offset based on day of week January 1 fell on
set /a Offset=%3-1900
set /a Offset=((%Offset%+(%Offset%/4))%%7)+6
REM Find out what day of the year (from January 1) we are on
call :DayNumber %1 %2 %3
REM Add offset and then divide by 7 days per week
set /a Week=(%Day%+%Offset%)/7
goto :EOF 
:DayNumber
REM Incrementally build up dy number from month and day
set /a Day=0
goto :DayNumber%1
:DayNumber12
set /a Day+=30
:DayNumber11
set /a Day+=31
:DayNumber10
set /a Day+=30
:DayNumber9
set /a Day+=31
:DayNumber8
set /a Day+=31
:DayNumber7
set /a Day+=30
:DayNumber6
set /a Day+=31
:DayNumber5
set /a Day+=30
:DayNumber4
set /a Day+=31
:DayNumber3
set /a Day+=28
REM Add an extra day on leap years
set /a Leap=%3 %% 4
if %Leap% == 0 set /a Day+=1
:DayNumber2
set /a Day+=31
:DayNumber1
set /a Day+=%2
goto :EOF
Random Solutions  
 
programming4us programming4us