Doing Time Offsets of HH/MM/SS and getting the MM/DD/YYYY/HH/MM/SS right

Dates and times in AppleScript are fairly straightforward. It is rather flexible about what it will coerce to a date, but the results depend on your settings in International System Preferences. To enter a date and time, the following works well for US systems:

theDate = date(“mm/dd/yyyy”) + hhhours + mmminutes + ss

where

mm = month
dd = day
yyyy = 2 or 4 digit year
hh = hour
mm = minute
nn = second

AppleScript measures and stores time in seconds. This is why the ss value isn’t multiplied by any term. The AppleScript terms “minutes” and “hours” represent the number of seconds in a minute or an hour. Likewise the term “days”, “weeks”, or “months” represent the number of seconds in a day, a week or a month.

to add “n” seconds, minutes, hours, days, etc:

  • n
  • n * minutes
  • n * hours
  • n * days
    etc.

AppleScript takes care of any rollover; hence if an addition or subtraction goes beyond the end/start of a day, month or year, the answer will be correct.

More information at: http://macscripter.net/viewtopic.php?id=24737&p=1

Regards,

Eric