DateAdd

Modifies a date object by date part and integer time unit

Method Signature

DateAdd(datepart=[string], number=[number], date=[any])

Arguments

Argument
Type
Required
Description
Default

datepart

string

true

The date part to modify

number

number

true

The number of units to modify by

date

any

true

The date object to modify

Examples

Add Days to a Date

Add 30 days to August 3rd, 2014.

Run Example

dateAdd( "d", 30, "8/3/2014" );

Result: {ts '2014-04-07 00:00:00'}

Subtract Days from a Date

Subtract 30 days from August 3rd, 2014.

Run Example

dateAdd( "d", -30, "8/3/2014" );

Result: {ts '2014-02-06 00:00:00'}

Add Weeks to a Date

Here we're adding 8 weeks to the date August 3rd, 2014.

Run Example

dateAdd( "ww", 8, "8/3/2014" );

Result: {ts '2014-05-03 00:00:00'}

Add Days to a Date (Member Function)

Here we're adding 1 day to the current date/time.

Run Example

createDate( 2022, 10, 1 ).add( "d", 1 );

Result: {ts '2022-10-02 00:00:00'}

Additional Examples

Run Example

// the below code increments 10 milliseconds in actual date
dump( dateAdd( "l", 10, now() ) );
// the below code increments 60 seconds in actual date
dump( dateAdd( "s", 60, now() ) );
// the below code increments 60 minutes in actual date
dump( dateAdd( "n", 60, now() ) );
// the below code increments 2 hours in actual date
dump( dateAdd( "h", 2, now() ) );
// the below code increments 1 day in actual date
dump( dateAdd( "d", 1, now() ) );
// the below code increments 1 month in actual date
dump( dateAdd( "m", 1, now() ) );
// the below code increments 1 year in actual date
dump( dateAdd( "yyyy", 1, now() ) );

Last updated

Was this helpful?