• 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: Date computation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date computation


  • Subject: Re: Date computation
  • From: Nigel Garvey <email@hidden>
  • Date: Sun, 9 Jan 2005 15:02:12 +0000

Nigel Garvey wrote on Fri, 7 Jan 2005 10:56:00 +0000:

>Michelle Steiner wrote on Fri, 7 Jan 2005 01:18:28 -0700:

>>I've run into a brick wall here.  I'm trying to compute the date of the
>>second Wednesday of the current month, and if the current date is later
>>than or equal to that date, then compute the date of the second
>>Wednesday of the following month.
>
>  set today to (current date)
>  copy today to b
>  set b's day to 14
>  set secondWednesday to b - (b - (date "Wednesday, 1 January 1000
>00:00:00")) mod weeks
>  if secondWednesday is less than or equal to today then
>    tell b to set {day, day} to {32, 14}
>    set secondWednesday to b - (b - (date "Wednesday, 1 January 1000
>00:00:00")) mod weeks
>  end if
>  return secondWednesday

And now here's a version that's not only a little quicker, but is
apparently proof against all known, current AppleScript date bugs. It
should therefore work for any input date where the result falls within
the AppleScript date range:

  set today to (current date)
  copy today to b
  set b's day to 14
  tell (date "Wednesday, 1 January 1000 00:00:00") to ¬
    set secondWednesday to it - (it - b) div weeks * weeks
  if (secondWednesday is less than or equal to today) then
    set secondWednesday's day to (secondWednesday's day) + 28
    set secondWednesday's day to (secondWednesday's day) mod 7 + 7
  end if
  return secondWednesday

NG
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Date computation
      • From: Joseph Weaks <email@hidden>
  • Prev by Date: Re: FTP Server to dynamically create users
  • Next by Date: Re: Converting Hex to binary
  • Previous by thread: Re: Date computation
  • Next by thread: Re: Date computation
  • Index(es):
    • Date
    • Thread