JavaScript

Datesame Method

Syntax

Date.same(scope,[date[,format]]])

Arguments

scopestring

The scope of similarity. This can be "year", "quarter", "month", "week", "day" (or "date"), "hour", "minute" or "second".

datestringdatearray

The date to compare the given date with. If no value is passed in the date will be compared to the current date.

formatstring

If the passed in date is a string, this will specify the format the date is in. If no format is specified the default format in A5.d.date.format will be used. See Date.toFormat for a full list of format values.

Returns

sameboolean

Whether or not the dates are in the same given scope.

Description

Extension to the native date variable to allow for checking if one date is the same as another in a given time scope.

Discussion

The Date.same method allows to checking if a date is the same as another date or now in the context of a given scope.

This means that you can check to see if two dates are in the same "year", "quarter", "month", "week", "day" (or "date"), "hour", "minute" or "second".

Example

var d = new Date(2018,9,1);
var d2 = new Date(2018,8,30);
var s = d.same('year',d2);
// s  = true
s = d.same('quarter',d2);
// s = false;
s = d.same('week',d2);
// s = true