literal short date

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
drOrganized
Posts: 24
Joined: Tue Dec 04, 2007 7:02 pm
Location: Saratoga Springs

literal short date

Post by drOrganized » Sat Sep 17, 2011 5:25 pm

I have a problem where the short date is being treated as a division problem in a function:

function calculateAge tBirthday
....
end calculateAge


Here, contents of tBirthday: 11/18/47 is converted to 0.0028 automatically, and thus not available as a short date....

How can I prevent the date in a variable from being treated like numbers to be divided?

Thank you....

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

Re: literal short date

Post by jmburnod » Sat Sep 17, 2011 7:27 pm

Hi drOrganized,

I tested this way, it work but i'm sur someone have a more simple

Code: Select all

on GetBirthday 
   put calculateAge("9/17/1984") into tmes
   answer tmes
end GetBirthday

function calculateAge tBirthday --month,day,long year "5/3/1984" 
   get the long date 
   put the value of item-1 of it into tYearNow
   convert it to short date
   set the itemdel to"/"
     put the value of  item-1 of tBirthday into tYearBirthday
   put tYearNow into item -1 of it
    put tYearNow -tYearBirthday into tAge
   if item 1 to 2 of it = item 1 to 2 of tBirthday then
      put "Happy birthday, you're"&&tAge&&"old" into rcalculateAge
   else
      put "You're"&&tAge&&"old" into rcalculateAge
   end if
   set the itemdel to","
 return rcalculateAge
end calculateAge
Best regards

Jean-Marc
https://alternatic.ch

drOrganized
Posts: 24
Joined: Tue Dec 04, 2007 7:02 pm
Location: Saratoga Springs

Re: literal short date

Post by drOrganized » Sat Sep 17, 2011 7:47 pm

Hi Jean Marc,

I understand your code, and it is nearly identical to the code I am using for the rest of the calculate age handler. The problem is that when I write:

put "11/18/1947" into tBirthday
put calculateAge(tBirthday) into tAge


the calculateAge function receives tBirthday as (11 divided by 18 divided by 1947). Hence, my question, how can you prevent the short date from being treated as numbers to be divided?

Thanks for considering...

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: literal short date

Post by sturgis » Sat Sep 17, 2011 8:21 pm

Can you post your code? Sounds like something wonky is going on.

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

Re: literal short date

Post by jmburnod » Sat Sep 17, 2011 10:26 pm

Hi drOrganized
how can you prevent the short date from being treated as numbers to be divided?
It is difficult for me to explane in english, but i try.

1. The short date don't give the century
2. To get the year you need the last item of the long date only. For that check itemdel
3. It seem it is safe to use "the value of" for calculation

All the best

Jean-Marc
https://alternatic.ch

drOrganized
Posts: 24
Joined: Tue Dec 04, 2007 7:02 pm
Location: Saratoga Springs

Re: literal short date

Post by drOrganized » Sat Sep 17, 2011 10:36 pm

Hi Jean-Mar,

I tried:

put calculateAge(quote & tBirthday & quote) into tAge

and now it works fine, although I must remove the quotes in the function...

Strange thing is that I never had this problem in the past. It just started happening...

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

Re: literal short date

Post by jmburnod » Sun Sep 18, 2011 12:02 pm

H drOrganized,
put calculateAge(quote & tBirthday & quote) into tAge
Yes
put 3/7/98 return 0.0004373
put "3/7/98" return 3/7/98

Best

Jean-Marc
https://alternatic.ch

Post Reply

Return to “Talking LiveCode”