I am trying to create two dynamic dates in html/javascript/jquery. I want the dates to be formatted like yyyy/mm/dd. The first date will return the last day of the previous month, and the second date will return the last day of the current month. Anyone know how to do this in the technologies listed above?
I am 99.9999% positive I can accomplish this by making a call to a backend page using C#, but I want to see if there is a more efficient way to do this right in the DOM (is DOM the correct terminology?).
From a previous question on SO, here is the code I am using now…
var d = new Date();
document.write(new Date(d.getFullYear(), d.getMonth() + 1, 0, 23, 59, 59));
It seems like you already have most of the answer:
Then to format them how you want you can use:
jsFiddle here.
Edit
With two-digit month (last day should always be two digits):