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

  • 6 months 2 weeks ago
    1.27.2 update
  • 6 months 3 weeks ago
    Drupal 10/11 config
  • 6 months 4 weeks ago
  • PHP
    6 months 4 weeks ago
    PHP 8.3.11 and AlmaLinux
  • 6 months 4 weeks ago
    New version of Pound