Welcome, guest | Sign In | My Account | Store | Cart

Includes batch routines for day of week, is leap year and last dat of the month

Batch, 34 lines
 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
@echo off
setlocal enabledelayedexpansion
set /p yr= Enter year:
echo. 
call:monthdays %yr% list 
set mm=1
for %%i in (!list!) do (
  call:calcdow !yr! !mm! %%i dow
  set/a lsu=%%i-dow
  set mf=0!mm!
  echo !yr!-!mf:~-2!-!lsu! 
  set /a mm+=1
)
exit /b

:monthdays yr &list
setlocal
call:isleap %1 ly
for /L %%i in (1,1,12) do (
  set /a "nn = 30 + ^!(((%%i & 9) + 6) %% 7) + ^!(%%i ^^ 2) * (ly - 2)
  set list=!list! !nn!
)
endlocal & set %2=%list%
exit /b

:calcdow yr mt dy &dow  :: 0=sunday
setlocal
set/a a=(14-%2)/12,yr=%1-a,m=%2+12*a-2,"dow=(%3+yr+yr/4-yr/100+yr/400+31*m/12)%%7"
endlocal & set %~4=%dow%
exit /b

:isleap yr &leap  :: remove ^ if not delayed expansion
set /a "%2=^!(%1%%4)+(^!^!(%1%%100)-^!^!(%1%%400))"
exit /b
Created by Antoni Gual on Tue, 7 Jun 2016 (MIT)
Batch recipes (42)
Antoni Gual's recipes (16)

Required Modules

  • (none specified)

Other Information and Tasks