• 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:46:41 -0500

> Subject: Re: A Difference of Months
> Date: Wed, 13 Mar 2002 03:30:53 +0000
> From: Nigel Garvey <email@hidden>

> Arthur J Knapp wrote on Tue, 12 Mar 2002 16:55:22 -0500:
>
>> So I need to find how many months difference there are between any
>> two dates.

> I knew I shouldn't have downloaded any more mail at this time of the
> morning...! ;-)

I am so glad that you did, thank you Nigel. :)


>> is. If they are 24 months or younger, I want to return a string that says
>> something like:
>>
>> "This person is 15 months old."
>>
>> where as if they are 25 or more months old, I simply want to return their
>> age in years:
>>
>> "This person is 29 years old."

I was hesitant to include the above, because I didn't want anyone
thinking that I needed help in concatenating strings... ;-)


> First thoughts: get the difference of the years, multiply by twelve, add
> the difference of the month numbers.

Great stuff. This is also Shane's observation. Why did it not occur to me?


> ... If the later date's day is less than
> the earlier's, subtract 1.
>
> on monthNum from dateObj -- "French Vanilla" variant
> --> Hack to get round bug when subtracting one pre-1904 date from
> another
> copy dateObj to dateTemp
> tell dateTemp's year
> if it comes before 1904 then set dateTemp's year to it + 2000
> end tell

> -- End hack

Thank you, I was beginning to wonder if the hack was ever going to
end... ;-)

> copy dateTemp to dateTemp2
> set month of dateTemp2 to January
> return (1 + (dateTemp - dateTemp2) div 2.5E+6)


> on DifferenceOfMonths(d1, d2)

> -- No need to copy the dates. The originals aren't affected.

Yeah, I know I was being a bit over cautious... :)

> -- Ensure that d1 represents the later date
> if (d1 < d2) then set {d1, d2} to {d2, d1}
>
> set wholeMonths to ((d1's year) - (d2's year)) * 12 + (monthNum from
> d1) - (monthNum from d2)
> if d1's day comes before d2's day then set wholeMonths to wholeMonths
> - 1

This is fantastic, thank you Nigel. I've thrown a bunch of dates at
this handler, and nothing seems to trip it up, great stuff!!!


> DifferenceOfMonths(date ("9th June 1790" as string), current date)
> --> "This person is 211 years old."

Wow, can I meet this person? ;-)


P.S. In my original posting, I used a date variable called, "myLastBath".
I hope everyone understands that I was making a joke. Really.

;-)


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.VivaLaData.com/>
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.

  • Follow-Ups:
    • Re: A Difference of Months
      • From: email@hidden (Michael Sullivan)
  • Prev by Date: Re: A Difference of Months
  • 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