Age Calculator

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Age Calculator

Post by maxs » Sun Aug 13, 2017 2:50 am

Has anyone come up with a way to determine the age and month of a person if given a date line 02/22/1877?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3482
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Age Calculator

Post by richmond62 » Sun Aug 13, 2017 10:43 am

Well, I hadn't until I saw your post!

Nothing like THAT on a Sunday to whet my teeth.
HD.jpg
HOT DATE.livecode.zip
Here's the stack
(92.16 KiB) Downloaded 60 times
I'm a sadistic "tiddly-pom" so I'll leave you to convert the seconds back into DAYS and YEARS.

bogs
Posts: 3712
Joined: Sat Feb 25, 2017 10:45 pm

Re: Age Calculator

Post by bogs » Sun Aug 13, 2017 2:13 pm

richmond62 wrote:I'm a sadistic "tiddly-pom" so I'll leave you to convert the seconds back into DAYS and YEARS.
Where is the Months then? :P
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3482
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Age Calculator

Post by richmond62 » Sun Aug 13, 2017 3:36 pm

DGHD372.jpg
DGHD373.jpg

bogs
Posts: 3712
Joined: Sat Feb 25, 2017 10:45 pm

Re: Age Calculator

Post by bogs » Sun Aug 13, 2017 4:04 pm

Awesome richmond, just pure awesome :lol:
Image

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Age Calculator

Post by maxs » Sun Aug 13, 2017 4:15 pm

Richmond,

Im impressed you were able to refer back to an old Hypercard book. Thanks, Max

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Age Calculator

Post by maxs » Sun Aug 13, 2017 4:32 pm

just divide by 31536000 to get the age.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2364
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Age Calculator

Post by jmburnod » Sun Aug 13, 2017 4:46 pm

Hi,
I'm afraid that is a little more complicate.
@Max
Are you sure that it works with a date < 1/1/1970 (as first post 1877)
Best regards
Jean-Marc

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6117
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Age Calculator

Post by dunbarx » Sun Aug 13, 2017 4:58 pm

It may be useful to read the thread "When was the Big Bang" to get old, old dates. 1877 is a no-brainer. The Jurassic era requires extra coding.

viewtopic.php?f=9&t=26619&p=138530&hili ... ng#p138530

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3482
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Age Calculator

Post by richmond62 » Sun Aug 13, 2017 5:23 pm

Im impressed you were able to refer back to an old Hypercard book.
At 55, I'm a bit of an old book . . . and perpetually fighting with my wife who wants to chuck things
out all the time.

She "went a bit funny" when I managed to retrieve a whole 5 years worth of her academic work she thought was lost forever from a
load of ZIP disks . . . which I read through a SCSI ZIP drive connected to a SCSI PCI card connected to a machine running Ubuntu Linux.

No more fights :wink:

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2364
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Age Calculator

Post by jmburnod » Sun Aug 13, 2017 5:23 pm

Finally, big bang was a sunday :D

SparkOut
Posts: 2015
Joined: Sun Sep 23, 2007 4:58 pm

Re: Age Calculator

Post by SparkOut » Sun Aug 13, 2017 6:49 pm

On Windows,1877 is not a date. Nothing existed before 1970.

http://quality.livecode.com/show_bug.cgi?id=4941


To me, this is the single most inexplicable (that it has not been addressed in all this time, and that I seem to be in a very small minority with this opinion), serious and unacceptable thing in the qcc

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2094
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Age Calculator

Post by [-hh] » Mon Aug 14, 2017 10:35 am

You could use Malte's libdate, see his announcement here:
viewtopic.php?p=123544#p123544

For the age in number of days see the second box at right of his demo stack from github
https://github.com/derbrill/libdate
shiftLock happens

SparkOut
Posts: 2015
Joined: Sun Sep 23, 2007 4:58 pm

Re: Age Calculator

Post by SparkOut » Mon Aug 14, 2017 1:48 pm

Thanks Hermann, I already know and use Malte's library.
I just find it incredible that something so fundamental is not being addressed natively.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2094
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Age Calculator

Post by [-hh] » Mon Aug 14, 2017 5:00 pm

My link was for the OP's question, not for you! How can you assume that?!

Of course you are right with your opinion about tdate and time on Win, but don't forget, that LC goes even 10 years back before the birth date of DOS ;-)

p.s.
I read the OP's question again, thoroughly. He doesn't need any date or time lib, as he is asking for years and months only, not for days or seconds.
So we have only 2 to 4 'direct' additions/subtractions and 2 comparisons to get the result (here 140 years and 5 months):

Code: Select all

on mouseUp
  answer yearsAndMonth(1877,02,22,2017,08,14) 
end mouseUp

function yearsAndMonth y1,m1,d1,y2,m2,d2
  put y2-y1 into y; put m2-m1 into m
  if d2 < d1 then subtract 1 from m
  if m<0 then
    subtract 1 from y; add 12 to m
  end if
  return y & " years and " & m & "months"
end yearsAndMonth
shiftLock happens

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”