Re: DaysBetweenDates - the easy way with Euphoria 4.0+

new topic     » goto parent     » topic index » view thread      » older message » newer message

Actually, the routine can be simplified further:

-- place this routine at the bottom of datetime.e: 
public function DaysBetweenDates(datetime d1, datetime d2) 
return diff(d1,d2)/DayLengthInSeconds 
end function 
-- test: 
include std/datetime.e as dt 
constant D1 = new(1950, 6, 28),  
         D2 = new(2016, 12, 7), 
         n = DaysBetweenDates(D1,D2),  
         D3 = add(D1, n, DAYS) -- should equal D2 
                
printf(1, "\n\tThere are %d days between  %s and %s \n\n",  
               {n,  
                   dt:format(D1, "%A, %B %d %Y"),  
                   dt:format(D2, "%A, %B %d %Y") 
                }) 
printf(1, "\n\t%s plus %d days = %s \n\n\t",  
               {   dt:format(D1,    "%A, %B %d %Y"), n,  
                   dt:format(now(), "%A, %B %d %Y") 
               })      
                     
-- output: 
 
-- There are 24269 days between  Wednesday, June 28 1950 and Wednesday, December 07 2016  
 
-- Wednesday, June 28 1950 plus 24269 days = Wednesday, December 07 2016  
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu