Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

how to compares dates in javascript

Avatar

Level 4

Good day everyone,

I'm trying to come up with a way to write a Fiscal Year piece of code and so far I'm just having issues finding the right functions in JavaScript to help me do this.

so far I got this:

var d1 = new Date("Dec 28, 2014");

var yr1= d1.getFullYear();

var stryr1=yr1.toString();

//var checkdateagainst="April 01, " + stryr1;

var CurDate = stryr1.substr(-2,2);

var yr2 = yr1 + 1;

var stryr2=yr2.toString();

var FutureDate = stryr2.substr(-2,2);

var fy= CurDate + "-" + FutureDate;

This works in giving me the FY format I'm looking for which is: YY-YY

So basically I need to check the current system date against the date that would be the cut off date for adding a new fiscal year.

So if current date(May 28 2014) > "April 01" (of this year) =yes, then this means that I'm in a new fiscal year and I want to add fy to my dropdown choices.


"April 1st" is static and never changes except for the year its in. I hope this makes sense if it doesn't I can try to clarify more or if you guys just know at least how to do a compare between 2 dates to see if one is bigger then the other (so-to-speak), It would be of great help to me.


Thank you very much

0 Replies