• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A Difference of Months
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Difference of Months


  • Subject: Re: A Difference of Months
  • From: Arthur J Knapp <email@hidden>
  • Date: Wed, 13 Mar 2002 10:29:19 -0500

> From: email@hidden
> Date: Tue, 12 Mar 2002 22:15:42 EST
> Subject: A Difference of Months

> This should solve the problem quickly without rotating through each month,
> although there could certain (very few, limited - 4 dates per year?)
> instances where the combination is inaccurate by a month.

;-)

Hopefully not the 4 dates that my clients would actually want to use.

;-)

> set Now to the current date

> set BirthDate to the current date
> set the year of BirthDate to 2001
> set the month of BirthDate to October
> set the day of BirthDate to 15

> set Difference to (Now - BirthDate)
> set NumOfDays to (((Difference / 60) / 60) / 24) as integer

> if (NumOfDays > 730) then

> -- calculate as years
> set AgeYears to (round (NumOfDays / 365) rounding down)
> set theAge to (AgeYears as string) & " Years old."

Right, but it might actually be safer/easier to go back to using
the actual year integers at this point:

if (NumOfDays > 730) then
set AgeYears to Now's year - BirthDate's year

rather than dividing by 365, which isn't going to be accurate for leap
years any way. (Well, I admit that there would have to be a WHOLE LOT
of time-difference between the two dates before this method would become
inaccurate). :)


> else
> -- calculate general months using 30.4 days per,
> -- then bracketing +/- 1 to find the perfect month
> set AgeMonths to (round ((NumOfDays) / 30.4) rounding down)
> if ((the day of Now as number) > (the day of BirthDate as number)) then
> set AgeMonths to AgeMonths - 1
> end if
> set theAge to (AgeMonths as string) & " Months old."

That's good stuff, Marc. Thank you. :)


P.S. A digression...

I assume 30.4 is the statistical average number of days in 1 month?
Let me check that out...

-- Average 3 out of every 4 years
--
set threePerFour to 365 / 12 --> 30.41666... --> 30.4

-- Average 1 out of "almost" every four years
--
set onePerFour to 366 / 12 --> 30.5, (A very nice fraction).


-- So a leap-year average would be something like this:
--
threePerFour + threePerFour + threePerFour + onePerFour

result / 4 --> 30.4375

All of the above bears in mind that AppleScript is not exactly
a high-precision language when it comes to math, (and neither
am I). ;-)


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://homepage.mac.com/richard23/>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Crunch numbers
  • Next by Date: Re: A Difference of Months
  • Previous by thread: Re: A Difference of Months
  • Next by thread: Re: A Difference of Months
  • Index(es):
    • Date
    • Thread