AppleScript Date Calculations

Calculations for determining the week of the year in AppleScript.

Taken from Dates & Times in AppleScripts

The following AppleScript subroutine can be used to help calculate the week of the year. It returns the number of weeks that have elapsed since date "1/1/0001":

on getDatesWeekNum(theDate)
set {dDate, dDateNum} to {"1/1/1000", 364878}
return ((theDate - (date dDate)) div days + dDateNum) div 7 + 1
end getDatesWeekNum

To find the week number of the current date, subtract the number returned by that subroutine for January 1 of the year with the number returned for the current date:

set currentWeekNumber to ((getDatesWeekNum(current date)) - (getDatesWeekNum(date ("1/1/" & (year of the (current date)) as string))))

Technology:

Recent Updates