Jump to content

Return next months last day


rpaterick

Recommended Posts

Fun, fun:

var d = new Date();
var currMonth = d.getMonth();
var currYear = d.getFullYear();
// determine month and year for next month (0 = January; 11 = December)= 
if (currMonth == 11) {
   var year = currYear + 1;
   var month = 0;
} else {
   var year = currYear;
   var month = currMonth + 1;
}
var monthText = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
// determine last day of next month
var lastDay = new Date(new Date(year, month+1, 1)-1).getDate();
// return long date
return monthText[month] + " " + lastDay + ", " + year;

Link to comment
Share on other sites

var d = Today();
d = new Date(d.getFullYear(), d.getMonth()+2, 0);
return FormatDate(d, "lm d, yyyy");

Admit it Dan; you were waiting for me to answer so you could snub me with the 3-line solution. LOL. The advantage to my code is that it looks more complicated to your boss, assuming he doesn't know JavaScript. :p

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...