@echo off & setlocal enableextensions
disabledelayedexpansion
if "%~3"=="" (
echo Usage: %~0 DD MM YYYY
echo No leading zeros
!
goto :EOF)
::
:: Get the date
set day=%~1
set month=%~2
set year=%~3
::
:: Call the day ordinal number subroutine
call :JDdayNumber %day% %month% %year% DayOrdinalNumber
::
:: Display the result
echo %day%.%month%.%year% Day ordinal number %DayOrdinalNumber%
endlocal & goto :EOF
::
:: ============================================================
:: Subroutine: Calculate a day's ordinal number within the year
:JDdayNumber day month year return_
setlocal enableextensions
enabledelayedexpansion
if %2 LEQ 2 (
set /a f=%1-1+31*^(%2-1^)
) else (
set /a a=%3
set /a b=!a!/4-!a!/100+!a!/400
set /a c=^(!a!-1^)/4-^(!a!-1^)/100+^(!a!-1^)/400
set /a s=!b!-!c!
set /a f=%1+^(153*^(%2-3^)+2^)/5+58+!s!
)
set /a return_=%f%+1
endlocal & set "%4=%return_%" & goto :EOF
The output might be e.g.
C:\_D\TEST>cmdfaq 17 9 2006
17.9.2006 Day ordinal number 260
::
:: ============================================================
:: Subroutine: Calculate a day's ordinal number within the year
:: Based on a posting by Herbert Kleebauer
:JDdayNumber d m y w
setlocal enableextensions
disabledelayedexpansion
set /a w= %1 +(!(%3 %% 4)-!(%3 %% 100)+!(%3 %% 400))*(!((%2-3)^&16))
set /a w=(%w%+(%2-1)*30+2*(!((%2-7)^&16))-1+((65611044^>^>(2*%2))^&3))
endlocal & set "%4=%w%" & goto :EOF
In the above
! Unary NOT operator
& Bitwise AND
%% Remainder (modulo) operator
>> Logical shift