Add to Date (DateAdd)
What is it?
DateAdd modifies a provided date string by adding either days, months or years to that date, then returns the resulting date as a string.
What is the Syntax?
The DateAdd function’s syntax is as follows:
DateAdd( DatePart, AddValue, InitialDate );
The DatePart argument must be set to “Day”, “Month” or “Year”, in quotes, and determines the unit type being added to the date.
AddValue must be given an integer value that can either be positive (for adding to the date) or negative (for subtracting from it).
Finally, InitialDate is a string containing your starting date.
Why might I want to use this?
The insurance quotes website we previously discussed has a strict policy of responding to all enquiries within seven calendar days. Therefore, each time a quote is requested, a second date is stored alongside the date of request, indicating the latest date that the customer should be contacted back. Agents at the insurance website can use this second date to keep track of outstanding quote requests, particularly those which are nearing the response deadline.
ResponseDate := DateAdd( "Day", 7, GetDate() );
This value is calculated at the same time as the quote is requested, ensuring the two values are synchronised.
In cases where the date is incremented by months, any date whose day value is higher than the total days in the new month will be reduced to the last day of the new month. For example, if you add 1 month to the date “31/01/2014”, rather than returning “31/02/2014” (an invalid date) the expression instead returns “28/02/2014”, which is the closest available date in the correct month.
<< Previous: Date Difference (DateDiff) | Next: Date Comparison (DateCompare) >>