Page 1 of 1

literal short date

Posted: Sat Sep 17, 2011 5:25 pm
by drOrganized
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....

Re: literal short date

Posted: Sat Sep 17, 2011 7:27 pm
by jmburnod
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

Re: literal short date

Posted: Sat Sep 17, 2011 7:47 pm
by drOrganized
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...

Re: literal short date

Posted: Sat Sep 17, 2011 8:21 pm
by sturgis
Can you post your code? Sounds like something wonky is going on.

Re: literal short date

Posted: Sat Sep 17, 2011 10:26 pm
by jmburnod
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

Re: literal short date

Posted: Sat Sep 17, 2011 10:36 pm
by drOrganized
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...

Re: literal short date

Posted: Sun Sep 18, 2011 12:02 pm
by jmburnod
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