literal short date
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 24
- Joined: Tue Dec 04, 2007 7:02 pm
- Location: Saratoga Springs
literal short date
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....
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....
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: literal short date
Hi drOrganized,
I tested this way, it work but i'm sur someone have a more simple
Best regards
Jean-Marc
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
Jean-Marc
https://alternatic.ch
-
- Posts: 24
- Joined: Tue Dec 04, 2007 7:02 pm
- Location: Saratoga Springs
Re: literal short date
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...
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
Can you post your code? Sounds like something wonky is going on.
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: literal short date
Hi drOrganized
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
It is difficult for me to explane in english, but i try.how can you prevent the short date from being treated as numbers to be divided?
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
-
- Posts: 24
- Joined: Tue Dec 04, 2007 7:02 pm
- Location: Saratoga Springs
Re: literal short date
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...
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...
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: literal short date
H drOrganized,
put 3/7/98 return 0.0004373
put "3/7/98" return 3/7/98
Best
Jean-Marc
Yesput calculateAge(quote & tBirthday & quote) into tAge
put 3/7/98 return 0.0004373
put "3/7/98" return 3/7/98
Best
Jean-Marc
https://alternatic.ch