converting seconds to age

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

converting seconds to age

Post by marksmithhfx » Thu Jan 19, 2012 7:57 am

Does anyone have code to convert the difference between two dates, in seconds, to years? For example the difference between today and your date of birth expressed as your age?

Thanks

-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: converting seconds to age

Post by jmburnod » Thu Jan 19, 2012 9:37 am

Hi Mark,

I found a scripts on my HD to get the num of days between two date

Code: Select all

on tNumDaysBetweenDates
   put NumDaysBetweenDates("1/19/6","1/19/12")
end tNumDaysBetweenDates


function  NumDaysBetweenDates pStartDay,pEndDay
   put empty into rNumDaysBetweenDates
   put pStartDay into depDate
   put pEndDay into ArrDate
   put depDate into UnedateD
   convert unedateD to seconds
   put ArrDate into UnedateA
   convert unedateA to seconds
   put unedateA-unedateD into difSec
   put difSec/86400 into rNumDaysBetweenDates
   return rNumDaysBetweenDates
end NumDaysBetweenDates
Best regards

Jean-Marc
https://alternatic.ch

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: converting seconds to age

Post by marksmithhfx » Fri Jan 20, 2012 2:23 am

Thanks Jean-Marc, good start...

I guess rNumDaysBetweenDates/365.25 should get me pretty close if not exactly to the right answer. I do worry, when reporting age this way, of being off by one day but the errors should be few and minor.

-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: converting seconds to age

Post by dunbarx » Fri Jan 20, 2012 2:59 am

365.25 is accurate to 0.01 days, or about 15 minutes. This should do.

Craig Newman

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: converting seconds to age

Post by marksmithhfx » Fri Jan 20, 2012 3:44 am

dunbarx wrote:365.25 is accurate to 0.01 days, or about 15 minutes. This should do.

Craig Newman

Reassuring. Thanks

-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Post Reply