• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
        • AdjLBA Function
        • AdjLBI Function
        • AdjUBA Function
        • AdjUBI Function
        • DateAdd Function
        • DateDiff Function
        • DateValid Function
        • PublishDate Function
        • SetLB Function
        • SetUB Function
        • SysDate Function
        • SysTime Function
        • timestamp Function
        • timestring Function
      • External File Functions
      • Synchronization Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

DateAdd Function

Format
i = dateadd(start_date, periodʃ, period_typeʅ);
Description
The dateadd function calculates a new date by adding a period to a starting date. The numeric expression start_date must be in YYYYMMDD (year/month/day) format. If no year is present, then the current or previous year is assumed in order satisfy the condition that the date is not in the future (based on the computer's system clock). The numeric expression period is the amount of time that is added to the starting date, and defaults to days. Alternatively, an optional string expression, period_type, modifies the period, and can be one of the following values:
period_typeDescription
"d"days (default)
"w"weeks
"m"months
"y"years
If the period is not an integer, the period will be modified and the calculation will use days. For example, the following calculations are identical:
dateadd(20200319, 1.5, "y");
dateadd(20200319, 1.5 * 365.25, "d");
Return Value
The function returns a date calculated by adding the period to the starting date. If the starting date cannot be processed, the function returns default.
Examples
dateadd(20121225, 7);       // returns 20130101

dateadd(20120228, 1);       // returns 20120229
dateadd(20130228, 1);       // returns 20130301

dateadd(20040820, 3, "w");  // returns 20040910
dateadd(20040820, 3, "m");  // returns 20041120
dateadd(20040820, 3, "y");  // returns 20070820

dateadd(20001010, -3, "m"); // returns 20000710
See also: DateDiff Function, DateValid Function, SysDate Function