computing
  • 7

Solved MS DOS – How To Get The Day Difference Between

  • 7

MS DOS – How to get the day difference between two dates?

Share

1 Answer

  1. Test this. It is assumed that the second date will always be greater than the first, if not then you should code a routine to check this and branch to a suitable routine.

    @echo off
    cls
    setlocal
    
    set mm=7
    set dd=14
    set year=2011
    call :convjdate
    set juldate=%jdate%
    
    set mm=7
    set dd=20
    set year=2011
    call :convjdate
    set juldate1=%jdate%
    
    set /a daydiff=%juldate1%-%juldate%
    
    echo Difference=%daydiff% days.
    exit /b
    
    :convjdate
    :: Convert Gregorian date to Julian date
    :: Algorithm based on Fliegel-Van Flandern
    :: algorithm from the Astronomical Almanac,
    :: provided by Doctor Fenton on the Math Forum
    :: (http://mathforum.org/library/drmath/view/51907.html),
    :: and converted to batch code by Ron Bakowski.
    
    SET /A Month1 = ( %MM% - 14 ) / 12
    SET /A Year1  = %year% + 4800
    SET /A jdate  = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ^
    ( %MM% - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / ^
    100 ) ) / 4 + ^%DD% - 32075
    
    

    Please come back & tell us if your problem is resolved.

    • 0