Shane Shane - 3 months ago 9
Javascript Question

Get previous year start month/date and end month/date

How can i get the previous

year
start
date/month
and end
date/month


Below is the code, i have tried, but its not working...

var lastyear = new Date(new Date().getFullYear(), 0, 1);
lastyear.setFullYear(lastyear.getFullYear() - 1);
var start = (new Date(lastyear, 0, 1)).getTime(),
end = (new Date(lastyear, 11, 31)).getTime();


Technically i want
01/01/2015
to
12/31/2015
. What is the mistake i am doing here?

Answer
var lastyear = new Date(new Date().getFullYear() - 1, 0, 1);
var start = (new Date(lastyear.getFullYear(), 0, 1)).getTime(),
    end = (new Date(lastyear.getFullYear(), 11, 31)).getTime();

Is this the solution you are looking for?