DateAdd Function

Description:

This function returns a date to which a specified time interval has been added. The input date can be specified as a character string (DateInputString and DateInputStringFormat argument) or as a number of milliseconds since 1970 (MillisecondsSince1970Integer argument).

The format of the output date is specified in the DateOutputStringFormat argument.

Format:

result = DateAdd(DateInputString, DateInputStringFormat, DateOutputStringFormat, IntervalType, IntervalValueInteger);
result = DateAdd(MillisecondsSince1970Integer, DateOutputStringFormat, IntervalType, IntervalValueInteger);

Parameter:

DateInputString

Character string representing a date. The format of the date must be described in the DateInputFormatStringFormat

DateInputStringFormat

The DateInputStringFormat argument consists of one or more codes listed below:

%a Abbreviated weekday name.
%A Full weekday name.
%b Abbreviated month name
%B Full month name.
%c Local date and time representation.
%d Day of the month as decimal number (01 – 31).
%H Hour in 24-hour format (00 – 23).
%I Hour in 12-hour format (01 – 12).
%j Day of the year as decimal number (001 – 366).
%m Month as a decimal number (01 – 12).
%M Minutes as a decimal number (00 – 59).
%p Current location's A.M./P.M. indicator for 12-hour clock.
%S Seconds as a decimal number (00 – 59).
%s Seconds elapsed since midnight (00:00:00), January 1, 1970.
%F Milliseconds as a decimal number (000 – 999).
%f Milliseconds elapsed since midnight (00:00:00), January 1, 1970.
%U Week of the year as a decimal number, with Sunday as the first day of week (00 – 53).
%w Weekday as a decimal number (0 – 6; Sunday is 0).
%W Week of the year as a decimal number, with Monday as the first day of week (00 – 53).
%x Local date representation.
%X Local time representation.
%y Year without a century, as a decimal number (00 – 99).
%Y Year with a century, as a decimal number.
%z, %Z Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if the time zone is unknown.
%% Percent sign.

DateOutputStringFormat

Format of the output date (see DateInputStringFormat options).

IntervalType

Type of interval to add. It can be:

year
month
week
day
hour
minute
second

IntervalValueInteger

Integer containing the number of interval you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past

 

Example:

STRING TodayPlus_3_days;
STRING Today;

log dateadd("02-26-2010 16:00:00", "%m-%d-%Y %H:%M:%S", "%m-%d-%Y %H:%M:%S", day, 3); 
// today
Today = date("%m-%d-%Y %H:%M:%S");

// today + 3 days
TodayPlus_3_days = dateadd(Today , "%m-%d-%Y %H:%M:%S", "%m-%d-%Y %H:%M:%S", day, 3); 
log TodayPlus_3_days ;

// today + 3 days
TodayPlus_3_days = dateadd(tointeger(date("%f")), "%m-%d-%Y %H:%M:%S", day, 3);
log TodayPlus_3_days ;

Output:

03-01-2010 16:00:00
Set Variable: Today to value 08-23-2010 17:00:48
Set Variable: TodayPlus_3_days to value 08-26-2010 17:00:48
08-26-2010 18:00:48
Set Variable: TodayPlus_3_days to value 08-26-2010 17:00:48
08-26-2010 17:00:48





Go back to the Learning center:


Copyright © AgileLoad. All rights reserved.
Agile Load testing tool| Contact AgileLoad | Terms of Use | Sitemap