On 02.09.2021 17:51, Tom Del Rosso wrote:
> Zaidy036 wrote:
>> Make two batches <1>DateToJ and <2>DateToC. Run <1>, apply logic, run
>> <2>, generate folder name.
> That's great, although the two routines together are as long as mine.
Here an old batch which calculates the number of days since 1901
without using an IF statement:
@echo off
setlocal disabledelayedexpansion
:: extract the variables %y% %m% %d% from the %date% variable
:: (this depends on the local date format)
:: valid year range: 1901-2099
set /a y=2004
set /a m=3
set /a d=1
call :date2day
set /a w=%w%-1
call :day2date
echo %y% %m% %d%
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: convert the date in %y% %m% %d% to the number of days (%w%) ::
:: since 1901 (day 0 is 1. Jan. 1901) ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:date2day
set /a w=(%y%-1901)*365+(%y%-1901)/4+%d%-1+(!(%y% %% 4))*(!((%m%-3)^&16))
set /a w=(%w%+(%m%-1)*30+2*(!((%m%-7)^&16))-1+((65611044^>^>(2*%m%))^&3))
echo %y% %m% %d% %w%
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: convert the number of days in %w% to the date (%y% %m% %d%) ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:day2date
set /a x=%w%/1461
set /a w=%w%-%x%*1461
set /a z=%w%/365-((%w%/365)^>^>2)
set /a w=%w%-%z%*365
set /a y=1901+%x%*4+%z%
set /a v=%w%-!(%y% %% 4)
set /a m=!!(%w%/31)+!!(%v%/59)+!!(%v%/90)+!!(%v%/120)+!!(%v%/151)+!!(%v%/181)
set /a m=%m%+!!(%v%/212)+!!(%v%/243)+!!(%v%/273)+!!(%v%/304)+!!(%v%/334)+1
set /a d=%w%+1-(!(%y% %% 4))*(!((%m%-3)^&16))
set /a d=%d%-((%m%-1)*30+2*(!((%m%-7)^&16))-1+((65611044^>^>(2*%m%))^&3))
goto :eof