• 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: Subtract 1 month from date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subtract 1 month from date


  • Subject: Re: Subtract 1 month from date
  • From: kai <email@hidden>
  • Date: Thu, 9 Dec 2004 04:45:38 +0000


On Wed, 08 Dec 2004 15:37:21 -0800, Eric Geoffroy wrote:

Or 4 weeks I suppose. It's okay if it's not super precise.

I can say "d + 4 * weeks"
but it won't allow "d + 1 * months
and won't allow d - 1 * weeks

Output should look like this.

11/1/2004...12/1/2004

The idea is to coerce dates into range of past month for reporting porpoises. (purposes. I can't resist a good malapropism)

I guess I could coerce to numbers and do simple math like this: (pseudo code coming)
today's date as words
set mth to (word 1 as number) -1
set d to "1/" & mth & year


set dto (get current date )
set eto d- 4 * weeks
set {dMth ,dDay }to words of (short date string of d) -- DD/MM/YY
set eMth to first word of (short date string of e)
set strDate to (dMth & "/1/" & year of d)as text
set endDate to (eMth & "1/" & year of e)
set searchrange to strDate & "..." & endDate

It looks as if your dates could always default to the first day of a month. If that's the case, how about something like this:


---------------------

set e to current date
set e's day to 1
set s to e - days
set searchrange to ((s's month as integer) as string) & "/1/" & ¬
	s's year & "..." & (e's month as integer) & "/1/" & e's year

---------------------

The last line assumes you're running in Panther (which I'm currently not - so I'm just guessing how it might work). Alternatively, and borrowing blatantly from Nigel's suggestion, this may do it:

---------------------

on firstOfMonthUS(d)
	copy d to b
	set b's month to January
	((b - 2500000 - d) div -2500000 as string) ¬
		& "/1/" & d's year
end firstOfMonthUS

set e to current date
set e's day to 1
set s to e - days
set searchrange to firstOfMonthUS(s) ¬
	& "..." & firstOfMonthUS(e)

---------------------

---
kai
_______________________________________________
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


  • Prev by Date: Re: Indexing the month
  • Next by Date: Re: Filemaker
  • Previous by thread: Re: Subtract 1 month from date
  • Next by thread: Re: Subtract 1 month from date
  • Index(es):
    • Date
    • Thread