set theage to round (((current date) - b_date) / days / 365.2423)
rounding down
This formular will do for ages up to 90 very well.
This is, because the "the mean tropical year" is not exactly 365 days.
The exact value for the year 2000 is 365.242189670 days. Since days are
becoming shorter this value is not constant.
Greetings from Germany, Ronald
==============================
Am 27.03.2005 um 04:13 schrieb Robert DuToit:
On Mar 26, 2005, at 10:49 AM, Matt Neuburg wrote:
On Fri, 25 Mar 2005 12:46:09 -0500, Robert DuToit
<email@hidden>
said:
Hi all,
Maybe this is an applescript question but I am in the middle of
my
ASS app with a table with columns for a date (birth date) and age. I
want the age column to show the correct age of a person born on date
b_date. The simple solution below won't work over long periods of
time
because of leap years: Yours, Rob D
((Current date) - b_date) /days/365 -- won't be accurate in the long
run
--more complex solution below which works for me but..
--On other machine people get an error "can't make month into a
number
etc"
set xx to (current date)
set yy to b_date
set ee to (year of xx) - (year of yy)
if (year of xx) = (year of yy) then
set theage to 0
else if (month of xx) - (month of yy) > 0 then
set theage to ee
else if (month of xx) = (month of xx) and (day of xx)- (day of yy)
0 then
set theage to ee
else
set the theage to ee - 1
end if
return ee --the actual age of the person
--I could coerce (month of xx) to integer
So why don't you?
Well, I did and it also didn't work on OS 10.2.8 still generates
error "can't make month into number etc"... So I just tried the call
method date string instead of "Month of" and it works on older OS.
Voila!
set curdate to current date
set b_date to birth date
set cur_month to call method
"descriptionWithCalendarFormat:timeZone:locale:" of object curdate
with parameter "%m"
set birth_month to call method
"descriptionWithCalendarFormat:timeZone:locale:" of object curdate
with parameter "%m"
if cur_month > birth_month then etc etc... -- this works great
My bigger problem seems to be OS 10.2X since I use a lot of date
coercions in my table view which work fine on 10.3X but hit many snags
on the earlier OS. I don't know if there was a big change in
applescript or why there is such a big difference between the OS for
some pretty straight forward scripting. Time to move on to Tiger
instead perhaps? yours Rob D
but I am wondering if there is a simpler method ("Call method"?
or other) for this simple calculation
I don't understand what's not "simple" about what you're doing. When
you ask
me my age, I think (or, more likely, I ask you) what year this is,
and what
year I was born (I can remember that one on my own, thanks); then I
start
worrying about what the exact date is, i.e. is it before or after my
birthday. That is exactly what your code is doing - you've captured my
thought processes very well. :) m.
My mistake. I should have said more universal rather than simple.
Thanks, Rob D
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list
(email@hidden)
Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-studio/
email@hidden