Jump to content

Advancing the Date to Show future Month, Day, Year


monkeytooth

Recommended Posts

Well I've made a mess of things, I've seemed to compensate for somethings but forgot to compensate for the end of month. How can I take the code below and use it to Advance a month plus adjust the number of the day that will be shown. So lets say for example. Today, its October 31, 2010

 

In 2 days it will be November 2, 2010. The way I managed to mangle this together it will Show October 33, 2010. I'm so tired, and it's been over a month since I played with this code, so I need a fresh pair of eyes and some ideas to help me out.

 

var FutureMonth = 0;
var FutureDays = 2;
var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var d = new Date();
var curr_day = d.getDay();
var curr_date = d.getDate()+FutureDays;
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date ==31){sup = "st";}
else if (curr_date == 2 || curr_date == 22){sup = "nd";}else if (curr_date == 3 || curr_date == 23){sup = "rd";}
else{sup = "th";}
var curr_month;
var curr_year;
if((d.getMonth()+FutureMonth) > 12){
var diff_month = d.getMonth()+FutureMonth-12;
    curr_month = diff_month;
    curr_year = d.getFullYear()+1;
}else{
curr_month = d.getMonth()+FutureMonth;curr_year = d.getFullYear();
}
document.getElementById("TheFutureDate1").innerHTML =  m_names[curr_month] + " " + curr_date + "<SUP>"+ sup + "</SUP>";

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.