Re: DaysBetweenDates - the easy way with Euphoria 4.0+
- Posted by petelomax Dec 06, 2016
- 1168 views
For comparison, this is what that looks like in Phix:
add/uncomment at the bottom of builtins\timedate.e
global function timedate_diff(timedate td1, timedate td2) return timedate_to_seconds(td2)-timedate_to_seconds(td1) end function
test code (same output):
include builtins/timedate.e set_timedate_formats({"DD/MM/YYYY","Dddd, Mmmm dd yyyy"},2) constant BIRTH_DATE = parse_date_string("28/6/1950") constant DATE2 = date() constant secs = timedate_diff(BIRTH_DATE, DATE2) constant days = floor(secs/(24*60*60)) constant d3 = adjust_timedate(BIRTH_DATE, secs) printf(1, "There are %d days between %s and %s. \n\n", {days, format_timedate(BIRTH_DATE), format_timedate(DATE2) }) printf(1, "%s plus %d days = %s. \n\n", {format_timedate(BIRTH_DATE), days, format_timedate(d3 ) })
I might add that the OE version should probably use datetime:format() to distinguish it from text:format().