- addDays
- addHours
- addMilliseconds
- addMinutes
- addMonths
- addQuarters
- addSeconds
- addWeeks
- addYears
- differenceInDays
- differenceInHours
- differenceInMilliseconds
- differenceInMinutes
- differenceInMonths
- differenceInQuarters
- differenceInSeconds
- differenceInWeeks
- differenceInYears
- getDayOfYear
- getQuarterOfYear
- getWeekOfYear
- Interval
- isAfter
- isBefore
- isBetween
- isCurrentDay
- isCurrentHour
- isCurrentMinute
- isCurrentMonth
- isCurrentQuarter
- isCurrentSecond
- isCurrentWeek
- isCurrentWeekday
- isCurrentYear
- isDate
- isEqual
- isFriday
- isFuture
- isLeapYear
- isMonday
- isPast
- isSameDay
- isSameHour
- isSameMinute
- isSameMonth
- isSameQuarter
- isSameSecond
- isSameWeek
- isSameWeekday
- isSameYear
- isSaturday
- isSunday
- isThursday
- isTomorrow
- isTuesday
- isWednesday
- isYesterday
- max
- min
- subtractDays
- subtractHours
- subtractMilliseconds
- subtractMinutes
- subtractMonths
- subtractQuarters
- subtractSeconds
- subtractWeeks
- subtractYears
- toDate
Adds days to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsdaysnumber the amount of days to add
import { addDays } from 'tempus';
// => input: 2020-11-18 15:30:00
addDays(new Date(2020, 10, 18, 15, 30), 3);
// => output: 2020-11-21 15:30:00Returns Date the new calculated date
Adds hours to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondshoursnumber the amount of hours to add
import { addHours } from 'tempus';
// => input: 2020-11-18 15:30:00
addHours(new Date(2020, 10, 18, 15, 30), 3);
// => output: 2020-11-18 18:30:00Returns Date the new calculated date
Adds milliseconds to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsmillisecondsnumber the amount of milliseconds to add
import { addMilliseconds } from 'tempus';
// => input: 1605654000000 ms
addMilliseconds(new Date(2020, 10, 18), 100);
// => output: 1605654000100 msReturns Date the new calculated date
Adds minutes to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsminutesnumber the amount of minutes to add
import { addMinutes } from 'tempus';
// => input: 2020-11-18 15:30:00
addMinutes(new Date(2020, 10, 18, 15, 30), 50);
// => output: 2020-11-18 16:20:00Returns Date the new calculated date
Adds months to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsmonthsnumber the amount of months to add
import { addMonths } from 'tempus';
// => input: 2020-11-18 15:30:00
addMonths(new Date(2020, 10, 18, 15, 30), 1);
// => output: 2020-12-18 15:30:00Returns Date the new calculated date
Adds quarters to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsquartersnumber the amount of quarters to add
import { addQuarters } from 'tempus';
// => input: 2020-11-18 15:30:00
addQuarters(new Date(2020, 10, 18, 15, 30), 1);
// => output: 2020-02-18 15:30:00Returns Date the new calculated date
Adds seconds to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondssecondsnumber the amount of seconds to add
import { addSeconds } from 'tempus';
// => input: 1605654000000 ms
addSeconds(new Date(2020, 10, 18), 50);
// => output: 1605654050000 msReturns Date the new calculated date
Adds weeks to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsweeksnumber the amount of weeks to add
import { addWeeks } from 'tempus';
// => input: 2020-11-18 15:30:00
addWeeks(new Date(2020, 10, 18, 15, 30), 1);
// => output: 2020-11-25 15:30:00Returns Date the new calculated date
Adds years to the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsyearsnumber the amount of years to add
import { addYears } from 'tempus';
// => input: 2020-11-18 15:30:00
addYears(new Date(2020, 10, 18, 15, 30), 2);
// => output: 2022-02-18 15:30:00Returns Date the new calculated date
Calculates the difference between two date objects in days
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInDays } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInDays(value, other);
// => output: 945dReturns number the difference in days
Calculates the difference between two date objects in hours
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInHours } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInHours(value, other);
// => output: 22676hReturns number the difference in hours
Calculates the difference between two date objects in milliseconds
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInMilliseconds } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInMilliseconds(value, other);
// => output: 81634545060msReturns number the difference in milliseconds
Calculates the difference between two date objects in minutes
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInMinutes } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInMinutes(value, other);
// => output: 1360576minReturns number the difference in minutes
Calculates the difference between two date objects in months
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInMonths } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInMonths(value, other);
// => output: 31mReturns number the difference in months
Calculates the difference between two date objects in quarters
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInQuarters } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInQuarters(value, other);
// => output: 10qReturns number the difference in quarters
Calculates the difference between two date objects in seconds
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInSeconds } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInSeconds(value, other);
// => output: 81634545sReturns number the difference in seconds
Calculates the difference between two date objects in weeks
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInWeeks } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInWeeks(value, other);
// => output: 135wReturns number the difference in weeks
Calculates the difference between two date objects in years
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { differenceInYears } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30);
const other = new Date(2018, 3, 18, 20, 15, 0, 0);
differenceInYears(value, other);
// => output: 2yReturns number the difference in years
Calculates the number of days that passed since start of the year.
import { getDayOfYear } from 'tempus';
// => input: 2020-11-18 15:30:00
getDayOfYear(new Date(2020, 10, 18, 15, 30));
// => output: 323Returns number the number of days
Calculates the number of quarters that passed since start of the year.
import { getQuarterOfYear } from 'tempus';
// => input: 2020-11-18 15:30:00
getQuarterOfYear(new Date(2020, 10, 18, 15, 30));
// => output: 4Returns number the number of quarters
Calculates the number of weeks that passed since start of the year.
import { getWeekOfYear } from 'tempus';
// => input: 2020-11-18 15:30:00
getWeekOfYear(new Date(2020, 10, 18, 15, 30));
// => output: 47Returns number the number of weeks
An interval
Type: Object
Checks if the first date object is after the second date object.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isAfter } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2019, 11, 6, 16, 35, 50);
isAfter(value, other);
// => output: trueReturns boolean true if the first date is after second date
Checks if the first date object is before the second date object.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isBefore } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2019, 11, 6, 16, 35, 50);
isBefore(value, other);
// => output: falseReturns boolean true if the first date is before second date
Checks if the specified date is in the interval.
value(Date | number) a date object or a timestamp in millisecondsintervalInterval the Interval to ckeck
import { isBetween } from 'tempus';
isBetween(new Date(2020, 10, 18, 15, 30, 45), {
start: new Date(2020, 10, 1),
end: new Date(2020, 11, 1)
});
// => output: trueReturns boolean true if the date is in the interval
Checks if the specified date has the same amount of days as the current date.
import { isCurrentDay } from 'tempus';
isCurrentDay(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date has the same amount of days
Checks if the specified date has the same amount of hours as the current date.
import { isCurrentHour } from 'tempus';
isCurrentHour(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date has the same amount of hours
Checks if the specified date has the same amount of minutes as the current date.
import { isCurrentMinute } from 'tempus';
isCurrentMinute(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date has the same amount of minutes
Checks if the specified date is in same month as the current date.
import { isCurrentMonth } from 'tempus';
isCurrentMonth(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is in same month
Checks if the specified date is in same quarter as the current date.
import { isCurrentQuarter } from 'tempus';
isCurrentQuarter(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is in same quarter
Checks if the specified date has the same amount of seconds as the current date.
import { isCurrentSecond } from 'tempus';
isCurrentSecond(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date has the same amount of seconds
Checks if the specified date is in same week as the current date.
import { isCurrentWeek } from 'tempus';
isCurrentWeek(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is in same week
Checks if the specified date has the same weekday as the current date.
import { isCurrentWeekday } from 'tempus';
isCurrentWeekday(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date has the same weekday
Checks if the specified date is in same year as the current date.
import { isCurrentYear } from 'tempus';
isCurrentYear(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is in same year
Checks if an object is an instance of Date.
valueany the object to check
Returns boolean true if the object is a date
Checks if two date objects are equal.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isEqual } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isEqual(value, other);
// => output: trueReturns boolean true if the dates are equal
Checks if the specified date is on a friday.
import { isFriday } from 'tempus';
// => input: 2020-11-18 15:30:00
isFriday(new Date(2020, 10, 18, 15, 30));
// => output: falseReturns boolean true if the date is on a friday
Checks if the specified date is in the future.
import { isFuture } from 'tempus';
isFuture(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is in the future
Checks if the specified date is in a leap year.
import { isLeapYear } from 'tempus';
// => input: 2020-11-18 15:30:00
isLeapYear(new Date(2020, 10, 18, 15, 30));
// => output: trueReturns boolean true if the date is in a leap year
Checks if the specified date is on a monday.
import { isMonday } from 'tempus';
// => input: 2020-11-18 15:30:00
isMonday(new Date(2020, 10, 18, 15, 30));
// => output: falseReturns boolean true if the date is on a monday
Checks if the specified date is in the past.
import { isPast } from 'tempus';
isPast(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is in the past
Checks if two date objects have the same amount of days.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameDay } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameDay(value, other);
// => output: trueReturns boolean true if the dates have the same amount of days
Checks if two date objects have the same amount of hours.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameHour } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameHour(value, other);
// => output: trueReturns boolean true if the dates have the same amount of hours
Checks if two date objects have the same amount of minutes.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameMinute } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameMinute(value, other);
// => output: trueReturns boolean true if the dates have the same amount of minutes
Checks if two date objects are in the same month.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameMonth } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameMonth(value, other);
// => output: trueReturns boolean true if the dates are in the same month
Checks if two date objects are in the same quarter.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameQuarter } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameQuarter(value, other);
// => output: trueReturns boolean true if the dates are in the same quarter
Checks if two date objects have the same amount of seconds.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameSecond } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameSecond(value, other);
// => output: trueReturns boolean true if the dates have the same amount of seconds
Checks if two date objects are in the same week.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameWeek } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameWeek(value, other);
// => output: trueReturns boolean true if the dates are in the same week
Checks if two date objects have the same weekday.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameWeekday } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameWeekday(value, other);
// => output: trueReturns boolean true if the dates have the same amount of weekday
Checks if two date objects are in the same year.
value(Date | number) a date object or a timestamp in millisecondsother(Date | number) a date object or a timestamp in milliseconds
import { isSameYear } from 'tempus';
const value = new Date(2020, 10, 18, 15, 30, 45);
const other = new Date(2020, 10, 18, 15, 30, 45);
isSameYear(value, other);
// => output: trueReturns boolean true if the dates are in the same year
Checks if the specified date is on a saturday.
import { isSaturday } from 'tempus';
// => input: 2020-11-18 15:30:00
isSaturday(new Date(2020, 10, 18, 15, 30));
// => output: falseReturns boolean true if the date is on a saturday
Checks if the specified date is on a sunday.
import { isSunday } from 'tempus';
// => input: 2020-11-18 15:30:00
isSunday(new Date(2020, 10, 18, 15, 30));
// => output: falseReturns boolean true if the date is on a sunday
Checks if the specified date is on a thursday.
import { isThursday } from 'tempus';
// => input: 2020-11-18 15:30:00
isThursday(new Date(2020, 10, 18, 15, 30));
// => output: trueReturns boolean true if the date is on a thursday
Checks if the specified date is tomorrow.
import { isTomorrow } from 'tempus';
isTomorrow(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is tomorrow
Checks if the specified date is on a tuesday.
import { isTuesday } from 'tempus';
// => input: 2020-11-18 15:30:00
isTuesday(new Date(2020, 10, 18, 15, 30));
// => output: falseReturns boolean true if the date is on a tuesday
Checks if the specified date is on a wednesday.
import { isWednesday } from 'tempus';
// => input: 2020-11-18 15:30:00
isWednesday(new Date(2020, 10, 18, 15, 30));
// => output: falseReturns boolean true if the date is on a wednesday
Checks if the specified date is yesterday.
import { isYesterday } from 'tempus';
isYesterday(new Date(2020, 10, 18, 15, 30, 45));Returns boolean true if the date is yesterday
Selects the maximum date in an array of dates.
valuesDate an array of date objects
import { max } from 'tempus';
const dates = [
new Date(2020, 0, 30, 15, 30, 45),
new Date(2020, 5, 25, 15, 30, 45),
];
max(dates);
// => output: 2020-06-05 15:30:45Returns Date the maximum date object
Selects the minimum date in an array of dates.
valuesDate an array of date objects
import { min } from 'tempus';
const dates = [
new Date(2020, 0, 30, 15, 30, 45),
new Date(2020, 5, 25, 15, 30, 45),
];
min(dates);
// => output: 2020-01-30 15:30:45Returns Date the minimum date object
Subtracts days from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsdaysnumber the amount of days to add
import { subtractDays } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractDays(new Date(2020, 10, 18, 15, 30), 3);
// => output: 2020-11-15 15:30:00Returns Date the new calculated date
Subtracts hours from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondshoursnumber the amount of hours to add
import { subtractHours } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractHours(new Date(2020, 10, 18, 15, 30), 3);
// => output: 2020-11-18 12:30:00Returns Date the new calculated date
Subtracts milliseconds from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsmillisecondsnumber the amount of milliseconds to add
import { subtractMilliseconds } from 'tempus';
// => input: 1605654000000 ms
subtractMilliseconds(new Date(2020, 10, 18), 100);
// => output: 1605653999900 msReturns Date the new calculated date
Subtracts minutes from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsminutesnumber the amount of minutes to add
import { subtractMinutes } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractMinutes(new Date(2020, 10, 18, 15, 30), 50);
// => output: 2020-11-18 14:40:00Returns Date the new calculated date
Subtracts months from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsmonthsnumber the amount of months to add
import { subtractMonths } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractMonths(new Date(2020, 10, 18, 15, 30), 1);
// => output: 2020-10-18 15:30:00Returns Date the new calculated date
Subtracts quarters from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsquartersnumber the amount of quarters to add
import { subtractQuarters } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractQuarters(new Date(2020, 10, 18, 15, 30), 1);
// => output: 2020-08-18 15:30:00Returns Date the new calculated date
Subtracts seconds from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondssecondsnumber the amount of seconds to add
import { subtractSeconds } from 'tempus';
// => input: 1605653950000 ms
subtractSeconds(new Date(2020, 10, 18), 50);
// => output: 1605654050000 msReturns Date the new calculated date
Subtracts weeks from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsweeksnumber the amount of weeks to add
import { addWeeks } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractWeeks(new Date(2020, 10, 18, 15, 30), 1);
// => output: 2020-11-11 15:30:00Returns Date the new calculated date
Subtracts years from the date object and returns a new instance, so the original object stays unchanged.
value(Date | number) a date object or a timestamp in millisecondsyearsnumber the amount of years to add
import { subtractYears } from 'tempus';
// => input: 2020-11-18 15:30:00
subtractYears(new Date(2020, 10, 18, 15, 30), 2);
// => output: 2022-02-18 15:30:00Returns Date the new calculated date
Converts any type to a date object. If the specified value is already a date, it returns just the value. If the value is a number, it will be converted with Date(milliseconds) constuctor. If the value anything else, a invalid date will be returned.
valueany the type to convert to a date
import { toDate } from 'tempus';
// => input: 2020-11-18 15:30:00
toDate(new Date(2020, 10, 18, 15, 30));
// => output: 2020-11-18 15:30:00
// => input: 1605709845060
toDate(1605709845060);
// => output: 2020-11-18 15:30:00
// => input: "Hello World"
toDate("Hello World");
// => output: Date(NaN) => Invalid dateReturns Date the converted date object