back to Overview

_.dateAdd()

Adds the specified time to the given Date and returns the result as a new Date .
Util module only.

Syntax

_.dateAdd(date, property, value)

Parameters

date
the Date to add to
property
a property name to represent the unit of the value. Can be 'fullYear', 'month', 'date', 'hours', 'minutes', 'seconds' or 'milliseconds'.
value
the amount to add
(return value)
the new Date copy

Description

Adds the specified time to the given Date and returns the result as a new Date . The unit for the value can be any Date property that has get and set methods: 'fullYear', 'month', 'date', 'hours', 'minutes', 'seconds' or 'milliseconds'.

Example

Calculate some dates based on the current time:

var now = new Date();
var yesterday = _.dateAdd(now, 'date', -1);
var inOneHour = _.dateAdd(now, 'hours', 1);
var tomorrow = _.dateAdd(now, 'date', 1);
var inThreeMonths = _.dateAdd(now, 'month', 3);

Comments

comments powered by Disqus

back to Overview

Functions