Skip to content

JavaScript Dates

Date to string

> date.toLocaleDateString();
'2022-09-08'

Handle month offset

Example

  • Fiscal year starts in April (month offset = 3)

Useful for getting the quarter

date = new Date("Jan 17, 1995"); // Jan is actually Q4
offset = 3;
date.setMonth(date.getMonth() - offset) > date;
1994 - 10 - 17;

Temporal API


Last update: 2023-04-24