Q: Reverse look up week number.
I had some help with this in the past and I had someone help create a week number based around my work's system.
If I know the week number can I use it to look up the week commencing date?
So for example we are in week 1 (Wednesday, 24 August 2016 at 13:33:27) If I input week 1 , can I make set theStart of theweek to "Monday, 22 August 2016 at 00:00:00"?
set thisDate to current date
set theweekNumber to ((thisDate - (my augustThirdWeek(thisDate))) div 604800)
on augustThirdWeek(d) -- get the third monday of August
copy d to tDate
tell tDate
set {its day, its month, its time} to {15, 8, 0} -- start at August 15
repeat 2 times
repeat while (its weekday) is not Monday
set its day to (its day) + 1 -- add one day (range 16 ... 21)
end repeat
if d < it then -- this date is older that the third Monday of August
set {its day, its year} to {15, (its year) - 1} -- subtract one year
else
return it
end if
end repeat
end tell
end augustThirdWeek
iMac, OS X Mavericks (10.9.4)
Posted on Aug 24, 2016 5:57 AM
Hi,
if you want a date like ("Monday, 22 August 2016 00:00:00" for the first week, "Monday, 29 August 2016 00:00:00" for the second week, and so on):
Try this script (work when Monday is the first day of the week):
---------------
set thisMonday to my mondayFromThisWeekNumber(1)
on mondayFromThisWeekNumber(weekNum)
tell (current date)
set {its day, its month, its time} to {15, 8, 0} -- start at August 15
set tDate to it + (weekNum * weeks) -- add weeks
end tell
tell tDate
repeat while (its weekday) is not Monday
set its day to (its day) - 1 -- subtract one day
end repeat
return it
end tell
end mondayFromThisWeekNumber
---------------
Posted on Aug 24, 2016 11:03 AM