Re: Date question with weeknumber
Re: Date question with weeknumber
- Subject: Re: Date question with weeknumber
- From: Stan Cleveland <email@hidden>
- Date: Fri, 23 Apr 2010 02:30:07 -0700
- Thread-topic: Date question with weeknumber
On 4/23/10 1:38 AM, "Bert Groeneveld" wrote:
> At some point in my script I know a weeknumber, for example set
> myWeeknumber to "03", or set myWeeknumber to "52" (can be any
> weeknumber in the future).
> I want to find ou the date of the wednesday that falls in the week
> with weeknumber myWeeknumber (this will be my startDate).
> And I want to find out the date of the tuesday that falls in the week
> after the week with weeknumber myWeeknumber (this will be my endDate).
>
> The format of the startDate end endDate should be "23-04-2010" (23th
> of april of 2010).
>
> myWeeknumber is always a weeknumber in the future so when today falls
> in week 52 of a given (this) year and myWeeknumber is set to "2" or
> "02" then the startDate end the endDate fall in the next year of course.
>
> I was wondering if this can be done with Applescript and if yes,
> anyone would be so kind to post example code.
Hi Bert,
The code below should get you going in the right direction.
HTH,
Stan C.
on dateToString(theDate)
set {m, d, y} to {month, day, year} of theDate
set m to text -2 thru -1 of ("0" & (m as number))
set d to text -2 thru -1 of ("0" & d)
return (d & "-" & m & "-" & y)
end dateToString
set myWeeknumber to "02" -- may be integer or string
set yearStart to "1/1/2010" -- January 1 of year in question
set shift to (Wednesday as integer) - (weekday of date yearStart)
set sDate to (date yearStart) + (myWeeknumber * weeks) + (shift * days)
set startDate to dateToString(sDate)
-->"13-01-2010"
set endDate to dateToString(sDate + (6 * days))
--> "19-01-2010"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden