forum-msg-id-130582-edit

Original date:2016-12-06 13:46:09 Edited by: K_D_R Subject: DaysBetweenDates - the easy way with Euphoria 4.0+

-------------------------------------------------------------------------------------------------- 
--  add the following function to the bottom of OpenEuphoria 4.0+ std/datetime.e 
public function DaysBetweenDates(datetime d1, datetime d2) 
return floor((datetimeToSeconds(d2) - datetimeToSeconds(d1))/DayLengthInSeconds) 
end function 
--------------------------------------------------------------------------------------------------
-- test_DaysBetweenDates.ex 
 
include std/datetime.e as dt 
 
constant BIRTH_DATE = new(1950, 6, 28) 
constant DATE2 = now() 
 
integer n = DaysBetweenDates(BIRTH_DATE,   DATE2)  
 
constant d3 = add(BIRTH_DATE, n, DAYS) -- should equal DATE2 
 
printf(1, "There are %d days between  %s and %s. \n\n",  
          {n, 
            dt:format(BIRTH_DATE, "%A, %B %d %Y"),  
            dt:format(DATE2, "%A, %B %d %Y") 
          }) 
           
printf(1, "%s plus %d days = %s. \n\n",  
          { 
           dt:format(BIRTH_DATE, "%A, %B %d %Y"), n,  
           dt:format(d3, "%A, %B %d %Y" ) 
          })           
 
-- output: 
 
-- There are 24268 days between  Wednesday, June 28 1950 and Tuesday, December 06 2016  
 
-- Wednesday, June 28 1950 plus 24268 days = Tuesday, December 06 2016  
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu