LISTSERV Maestro 8.1-4 Help

Forward >> << Back Table Of Contents

Calculation Formulas

Back to Calculation Formulas Overview
Back to Functions Overview


Function "CalendarAdd"

CalendarAdd(datevalue, timezone, value, unit)

Function: Performs calendar arithmetic on the given timestamp and returns a new, modified timestamp. The timestamp given in the "datevalue" argument (represented in milliseconds since "Jan. 1st 1970, 00:00:00 GMT") is interpreted as a date/time in the given "timezone". To this date/time, the given number of days, weeks, months or years is then added, and the resulting date/time value is again returned as a timestamp value (again represented in milliseconds since "Jan. 1st 1970, 00:00:00 GMT").

Note that adding a day, week, month or year can not be broken down into a simple "add a certain number of hours (or minutes/seconds/milliseconds)" formula. Instead, the calendar arithmetic works as follows:

Of course it is also possible to add several days/months/weeks/years by specifying a value other than "1", or to specify a negative value to move into the past, instead of into the future.

Return-Type: Number

Arguments:
datevalue - Type Number: The original timestamp, as milliseconds since "Jan. 1st 1970, 00:00:00 GMT".

timezone - Type Text: The ID or value of the timezone that shall be used to interpret the timestamp as a date/time value. See here for possible timezone values.

value - Type Number: The amount that shall be added to the date/time value. This is combined with the "unit" to determine, how many days, weeks, months or years shall be added to the date/time value. Can be positive (move the date/time into the future) or negative (move the date/time into the past).

unit - Type Text: The unit for the amount that shall be added to the date/time value. The only allowed values are "days", "weeks", "months" and "years" (with this exact spelling, all lower-case).

Examples:
CalendarAdd(CurrentMillis, "PST", 1, "years")
(if executed at a certain time on the 1st of April of a certain year, it returns a milliseconds value that represents the exact same time on the 1st of April in the following year)

CalendarAdd(CurrentMillis, "PST", -4, "weeks")
(if executed at a certain time on a Tuesday of a certain week, it returns a milliseconds value that represents the exact same time on the Tuesday that was four weeks earlier)

CalendarAdd(CurrentMillis, "EST", 10, "months")
(if executed at a certain time on the 7th of a certain month, it returns a milliseconds value that represents the exact same time on the 7th in the month that is 10 months later)

CalendarAdd(CurrentMillis, "CET", -1, "days")
(if executed at a certain time, it returns a milliseconds value that represents the same time on the previous day - on most days of the year that is exactly 24 hours before the current time, but if executed on the last Sunday in March [begin of daylight saving time in CET], the difference is only 23 hours, and if executed on the last Sunday in October [end of daylight saving time in CET], the differences is 25 hours)

CalendarAdd(CurrentMillis, "GMT", -1, "days")
(if executed at a certain time, it returns a milliseconds value that represents the date/time that is exactly 24 hours before the current time - it's always exactly 24 hours because GMT does not have daylight saving time)

© 2002-2017 L-Soft Sweden AB. All rights reserved.