Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 41,982 of 42,547    |
|    Herbert Kleebauer to Chris Roberts    |
|    Re: DOS Batch program countdown days unt    |
|    02 Feb 22 18:05:59    |
      From: klee@unibwm.de              On 02.02.2022 16:02, Chris Roberts wrote:       > DOS Batch program to countdown days/year (countdown date)       >       > Hi,       > Maybe someone can assist?       > I am having trouble figuring out how to do this using a DOS/BATCH program.       >       > For instance.       > $ echo %date%%time%       > Wed 02/02/2022 9:54:30.16       >       > Would someone here know how I can subtract todays date from 11/8/22 to       easily see how many days I still have to go?              Below are two subroutines which convert a date to the       numbers of days since 1. Jan. 1901 and reverse. Just call       the subroutine :date2day for both dates and calculate       the difference.                            @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              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca