DateTimeAdd
- adds specified number of seconds/minutes/hours/days to datetime

Date/Time
(AFL 3.40)


SYNTAX DateTimeAdd( datetime, amount, interval = inDaily )
RETURNS NUMBER or ARRAY
FUNCTION The function adds specified amount of 'intervals' to input datetime array. Allows for example to calculate datetime 5 days back or 13 months into the future.

INPUT:

  • datetime - scalar or array - the datetime value to add to (for example returned by Now(), DateTime() or StrToDateTime/_DT or ConvertDateTime functions)
  • amount - number of 'intervals' to add (seconds/minutes/hours/days/etc - depending on interval parameter)
  • interval - specifies unit you want to add, supported units are in1Second, in1Minute, inHourly, inDaily, inWeekly, inMonthly, inQuarterly, inYearly

RETURNS:
datetime (scalar or array) - returned type depends on input

EXAMPLE // Example 1:

x =
Now( 5 ) ;
printf("11 days from now " + DateTimeToStr( DateTimeAdd( x, 11, inDaily ) ) ) ;

// Example 2 (commentary):

x =
Now(5);
printf( " now is " + DateTimeToStr( x ) );

for( shift = -12; shift <= 12; shift++ )
{
 printf("%g seconds from now is " + DateTimeToStr( DateTimeAdd( x, shift, 1 ) ) + "n", shift );
 printf("%g minutes from now is " + DateTimeToStr( DateTimeAdd( x, shift, in1Minute ) ) + "n", shift );
 printf("%g hours from now is " + DateTimeToStr( DateTimeAdd( x, shift, inHourly ) ) + "n", shift );
 printf("%g days from now is " + DateTimeToStr( DateTimeAdd( x, shift, inDaily ) ) + "n", shift );
 printf("%g weeks from now is " + DateTimeToStr( DateTimeAdd( x, shift, inWeekly ) ) + "n", shift );
 printf("%g months from now is " + DateTimeToStr( DateTimeAdd( x, shift, inMonthly ) ) + "n", shift );  
 printf("%g quarters from now is " + DateTimeToStr( DateTimeAdd( x, shift, inQuarterly ) ) + "n", shift );
 printf("%g years from now is " + DateTimeToStr( DateTimeAdd( x, shift, inYearly ) ) + "nn", shift );
}
SEE ALSO DateTimeDiff() function , DateTimeToStr() function , DateTimeConvert() function , DateTime() function

References:

The DateTimeAdd function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference