Number of days between 2 dates
simplsol at aol.com
Wed Apr 16 20:28:23 CEST 2014
One of the date issue you run into on OS X is that it has 23 hour and 25 hour days - when going from or to standard time.
Here is a solution I've been using for many years:
function ahsm_DaysBetweenDates firstDate,secondDate
# Calculates the days elapsed between two dates, entered in any order.
# Use "abs" in case the first date is later than the second.
# Use "round" & numberFormat "#." in case there is a fraction
# created dividing 86400 into the non-24 hr days
# beginning or ending Daylight Savings Time.
# Add 1 to the date to include both the first and second date,
# (if they are the same, it is one day reviewed - not zero days).
set the useSystemDate to true -- for international dates
--convert firstDate to seconds -- did not work with non-US dates
convert firstDate from abbr date to seconds
--convert secondDate to seconds
convert secondDate from abbr date to seconds
put abs (firstDate - secondDate) into vLapsedSeconds
set numberFormat to "#."
put round ((vLapsedSeconds/86400)) + 1 into vDays
On Apr 16, 2014, at 9:25 AM, jbv at souslelogo.com wrote:
> Hi list,
> I need to calculate the number of days between any date and
> january 1st of the same year.
> So I tried this :
> put "1/31/14" && "0:00 AM" into tdate
> convert tdate to long seconds
> put "1/1/14" && "0:00 AM" into date0
> convert date0 to long seconds
> put (tdate - date0)/86400
> which seems to work and returns an integer.
> When I try this as 1st line of my script :
> put "3/30/14" && "0:00 AM" into tdate
> it still works (returns 88).
> And suddenly, the following :
> put "3/31/14" && "0:00 AM" into tdate
> returns 88.958333
> Any idea ?
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode