Date

These are extensions to JavaScript's Date. See this documentation for all standard Date methods.

Static properties

MS_IN_SECOND number

The number of milliseconds in a second.

MS_IN_MINUTE number

The number of milliseconds in a minute.

MS_IN_HOUR number

The number of milliseconds in an hour.

MS_IN_DAY number

The number of milliseconds in a day.

SECONDS_IN_MINUTE number

The number of seconds in a minute.

SECONDS_IN_HOUR number

The number of seconds in a hour.

SECONDS_IN_DAY number

The number of seconds in a day.

MINUTES_IN_HOUR number

The number of minutes in a hour.

MINUTES_IN_DAY number

The number of minutes in a day.

HOURS_IN_DAY number

The number of hours in a day.

DAYS_IN_WEEK number

The number of days in a week.

MONTHS_IN_QUARTER number

The number of months in a quarter.

QUARTERS_IN_YEAR number

The number of quarters in a year.

MONTHS_IN_YEAR number

The number of months in a year.

SUNDAY number

The day index for Sunday.

MONDAY number

The day index for Monday.

TUESDAY number

The day index for Tuesday.

WEDNESDAY number

The day index for Wednesday.

THURSDAY number

The day index for Thursday.

FRIDAY number

The day index for Friday.

SATURDAY number

The day index for Saturday.

Methods

firstDayOfMonth

Returns the first day (of the week) of the month for the given year and month.

Parameters

year number

The year to use.

month number

The month to use. 1 = January, 2 = February, etc. (1-12)

dayIdx number

The day index to use. 0 = Sunday, 1 = Monday, etc. (0-6)

Return type

Date

Examples

lastDayOfMonth

Returns the last day (of the week) of the month for the given year and month.

Parameters

year number

The year to use.

month number

The month to use. 1 = January, 2 = February, etc. (1-12)

dayIdx number

The day index to use. 0 = Sunday, 1 = Monday, etc. (0-6)

Return type

Date

Examples

getHolidays

Returns the holidays for the given year and culture.

Parameters

cultureName string

The culture name or object to use for determining weekends and holidays.

Return type

CultureSpecificNonWorkingDays

Examples

addYears

Offset the date by the given amount of years. Returns a new Date and leaves the original the same.

Parameters

yearOffset number

The number of years to subtract from or add to the Date.

Return type

Date

Examples

addQuarters

Offset the date by the given amount of quarters. Returns a new Date and leaves the original the same.

Parameters

quarterOffset number

The number of quarters to subtract from or add to the Date.

Return type

Date

Examples

addMonths

Offset the date by the given amount of months. Returns a new Date and leaves the original the same.

Parameters

monthOffset number

The number of months to subtract from or add to the Date.

Return type

Date

Examples

addDays

Offset the date by the given amount of days. Returns a new Date and leaves the original the same.

Parameters

dayOffset number

The number of days to subtract from or add to the Date.

Return type

Date

Examples

addWorkDays

Offset the date by the given amount of workdays. Will skip over weekends by default and a culture name or object may be specified. Returns a new Date and leaves the original the same.

Parameters

workdayOffset number

The number of workdays to subtract from or add to the Date.

cultureName string | CultureSpecificNonWorkingDays

(optional) The culture name or object to use for determining weekends and holidays.

Return type

Date

Examples

addHours

Offset the date by the given amount of hours. Returns a new Date and leaves the original the same.

Parameters

hourOffset number

The number of hours to subtract from or add to the Date.

Return type

Date

Examples

addMinutes

Offset the date by the given amount of minutes. Returns a new Date and leaves the original the same.

Parameters

minuteOffset number

The number of minutes to subtract from or add to the Date.

Return type

Date

Examples

addSeconds

Offset the date by the given amount of seconds. Returns a new Date and leaves the original the same.

Parameters

secondOffset number

The number of seconds to subtract from or add to the Date.

Return type

Date

Examples

addMilliseconds

Offset the date by the given amount of seconds. Returns a new Date and leaves the original the same.

Parameters

msOffset number

The number of milliseconds to subtract from or add to the Date.

Return type

Date

Examples

clone

Creates a duplicate of the Date object.

Parameters

Return type

Date

Examples

daysInMonth

Returns the number of days in the given year and month.

Parameters

year number

(optional) The year.

month number

(optional) The month. 1 = January, 12 = December.

Return type

Date

Examples

diff

Calculates the difference with another Date.

Parameters

otherDate Date | string

A JavaScript Date object or an ISO 8601 formatted string.

absolute boolean

(optional) If true, will return a positive value for the difference.

Return type

DateDiffResult

Examples

diffAbs

Calculates the difference with another Date. Always returns a positive value, no matter what the order of comparison is (Future with Past or Past with Future). It is similar to calling 'diff' with the second parameter set to true.

Parameters

otherDate Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

DateDiffResult

Examples

isWeekend

Returns whether the date is a weekend. By default, this will use the default of Saturday and Sunday. You can also specify a culture name or object to use for determining weekends.

Parameters

cultureNameOrObject string | CultureSpecificNonWorkingDays

(optional) The culture name or object to use for determining weekends.

Return type

boolean

Examples

isHoliday

Returns whether the date is a holiday. By default this will return false, unless a culture name or object is specified and the date is a holiday in that culture.

Parameters

cultureNameOrObject string | CultureSpecificNonWorkingDays

(optional) The culture name or object to use for determining weekends and holidays.

Return type

boolean

Examples

isSameDay

Returns whether another Date is on the exact same day. This basically compares the year, month and day, but not the time part.

Parameters

otherDate Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

boolean

Examples

isFuture

Returns whether the Date object is in the future relative to the present date.

Parameters

Return type

boolean

Examples

isPast

Returns whether the Date object is in the past relative to the present date.

Parameters

Return type

boolean

Examples

isBetween

Returns whether the Date object is between two given dates.

Parameters

dateFrom Date | string

A JavaScript Date object or an ISO 8601 formatted string.

dateTo Date | string

A JavaScript Date object or an ISO 8601 formatted string.

Return type

boolean

Examples

startOfYear

Returns a duplicate of the Date object, with the time set to the start of the year (Jan 1st at 00:00:00)

Parameters

Return type

Date

Examples

endOfYear

Returns a duplicate of the Date object, with the time set the end of the year (Dec 31st at 23:59:59)

Parameters

Return type

Date

Examples

startOfQuarter

Returns a duplicate of the Date object, with the time set to the start of the quarter (1st of Jan/Apr/Jul/Oct at 00:00:00)

Parameters

Return type

Date

Examples

endOfQuarter

Returns a duplicate of the Date object, with the time set the end of the quarter (31st of Mar/Jun/Sep/Dec at 23:59:59)

Parameters

Return type

Date

Examples

startOfMonth

Returns a duplicate of the Date object, with the time set to the start of the month (Day 1 at 00:00:00)

Parameters

Return type

Date

Examples

endOfMonth

Returns a duplicate of the Date object, with the time set the end of the month (Day 28/29/30/31 at 23:59:59)

Parameters

Return type

Date

Examples

startOfDay

Returns a duplicate of the Date object, with the time set to the start of the day (00:00:00)

Parameters

Return type

Date

Examples

endOfDay

Returns a duplicate of the Date object, with the time set the end of the day (23:59:59)

Parameters

Return type

Date

Examples

toShortDateString

Returns a string representation of the date in the format YYYY-MM-DD

Parameters

Return type

string

Examples

toYear

Returns a duplicate of the Date object, with a specified year. If no parameter is specified, will set the date to the present year.

Parameters

yearOrDate Date | number | string

(optional) The year to change the date to.

Return type

Date

Examples

toPresentYear

Returns a duplicate of the Date object, set to the present year.

Parameters

Return type

Date

Examples

Last updated