ADD_TO_DATETIME
Last updated
Was this helpful?
Last updated
Was this helpful?
The function ADD_TO_DATETIME adds a given number of years, months, weeks, days, hours, minutes, seconds, or milliseconds from a given DateTime.
This function takes three pieces of input: a , a , and a . The string designates which value in the given DateTime will be modified: "year", "month", "week", "day", "hour", "minute", "second," or "millisecond". This function adds the given Number from the designated value, and returns the resulting .
datetime (required, type: DateTime) Any valid DateTime.
number (required, type: Number) The number of units to be added to one of the values in the given DateTime. This number can be negative; if given a negative number, ADD_FROM_DATETIME will add the negative number to the specified value in the DateTime, effectively performing a subtraction operation.
unit_string (required, type: string) The units in the given DateTime that will be modified: "year", "month", "week", "day", "hour", "minute", "second," or "millisecond". In order to be correctly parsed by ADD_TO_DATETIME, the given string must exactly match one of the possible values given by .
modified_datetime (type: DateTime) The DateTime that results from adding the given number of units to the given DateTime.
Assume all examples have access to the following DateTime object:
The following example takes the date and time described in example_date_and_time and adds 5 minutes to it. Not that the returned DateTime is identical to example_date_and_time, save for the minute value:
The following example takes the date and time described in example_date_and_time and adds 20 hours to it. Note how this results in a change not only in the hour value of the resulting DateTime, but also in the the day:
The following example takes the date and time described in example_date_and_time and adds -1 day to it. Note how this effectively subtracts 1 to the given day value:
If ADD_TO_DATETIME is given a unit_string it cannot parse, it simply returns the given DateTime unmodified, such as in the following example:
Adding negative values is the same as subtracting positive values, allowing ADD_TO_DATETIME to mimic the functionality of .
ADD_TO_DATETIME can be used in tandem with the function in order to create a DateTime specifying a future date and time, which is particularly valuable in the context of . For instance, to set an action to occur five minutes in the future, you can define the DateTime at which the action will occur as follows: