/    Sign up×
Community /Pin to ProfileBookmark

? Hi, I am using this script to show the date and a message related to that date. in the “var day, I have added +1, in order to get tomorrow’s date and the related message. I have notice this morning that tomorrow’s date is September 31, 2005 !!! Where did it go wrong ? Tks for your help. Martin.

The script follows:

<SCRIPT LANGUAGE=”JavaScript”>

<!– This script and many more are available free online at –>
<!– The JavaScript Source!! [url]http://javascript.internet.com[/url] –>

<!– Begin
var days = new Array();
var msgs = new Array();

days[0] = “September 26, 2005”;
msgs[0] = “<br><b>Tryout Session – Check the calendar !</b>”;

days[1] = “September 27, 2005”;
msgs[1] = “<br><b>Nothing Scheduled!</b>”;

days[2] = “September 28, 2005”;
msgs[2] = “<b><br>Tryout Session – Check the calendar !</b>”;

days[3] = “September 29, 2005”;
msgs[3] = “<br><b>Nothing Scheduled!</b>”;

days[4] = “September 30, 2005”;
msgs[4] = “<br><b>Final Team Roster Posted!</b>”;

days[5] = “October 1, 2005”;
msgs[5] = “<br><b>Nothing Scheduled!</b>”;

days[6] = “October 2, 2005”;
msgs[6] = “<br><b>Nothing Scheduled!</b>”;

days[7] = “October 3, 2005”;
msgs[7] = “<b>PRACTICE – Check the calendar!</b>”;

days[8] = “October 4, 2005”;
msgs[8] = “<br><b>Nothing Scheduled!</b>”;

days[9] = “October 5, 2005”;
msgs[9] = “<b><br>PRACTICE – Check the calendar!</b>”;

days[10] = “October 6, 2005”;
msgs[10] = “<br><b>Nothing Scheduled!</b>”;

days[11] = “October 7, 2005”;
msgs[11] = “<b><br>Nothing Scheduled</b>”;

days[12] = “October 8, 2005”;
msgs[12] = “<br><b>Game vs St. Anthony’s – Check the calendar!</b>”;

days[13] = “October 9, 2005”;
msgs[13] = “<br><b>Nothing Scheduled!</b>”;

days[14] = “October 10, 2005”;
msgs[14] = “<br><b>Nothing Scheduled!</b>”;

days[15] = “October 11, 2005”;
msgs[15] = “<br><b>Nothing Scheduled!</b>”;

days[16] = “October 12, 2005”;
msgs[16] = “<b><br>Nothing Scheduled</b>”;

days[17] = “October 13, 2005”;
msgs[17] = “<br><b>Nothing Scheduled</b>”;

days[18] = “October 14, 2005”;
msgs[18] = “<br><b>Nothing Scheduled!</b>”;

days[19] = “October 15, 2005”;
msgs[19] = “<br><b>Nothing Scheduled!</b>”;

days[20] = “October 16, 2005”;
msgs[20] = “<br><b>Nothing Scheduled!</b>”;

days[21] = “October 17, 2005”;
msgs[21] = “<b><br>Nothing Scheduled</b>”;

days[22] = “Ocober 18, 2005”;
msgs[22] = “<br><b>Nothing Scheduled</b>”;

days[23] = “October 19, 2005”;
msgs[23] = “<br><b>Nothing Scheduled</b>”;

days[24] = “October 20, 2005”;
msgs[24] = “<b><br>PARENT’S MEETING – Check the calendar</b>”;

days[25] = “October 21, 2005”;
msgs[25] = “<br><b>Nothing Scheduled!</b>”;

days[26] = “October 22, 2005”;
msgs[26] = “<br><b>Nothing Scheduled!</b>”;

days[27] = “October 23, 2005”;
msgs[27] = “<br><b>Nothing Scheduled!</b>”;

days[28] = “October 24, 2005”;
msgs[28] = “<b><br>Nothing Scheduled</b>”;

days[29] = “October 25, 2005”;
msgs[29] = “<br><b>Nothing Scheduled!</b>”;

days[30] = “October 26, 2005”;
msgs[30] = “<b><br>Nothing Scheduled</b>”;

days[31] = “October 27, 2005”;
msgs[31] = “<br><b>Nothing Scheduled!</b>”;

days[32] = “October 28, 2005”;
msgs[32] = “<br><b>Nothing Scheduled!</b>”;

days[33] = “October 29, 2005”;
msgs[33] = “<br><b>Nothing Scheduled!</b>”;

days[34] = “October 30, 2005”;
msgs[34] = “<br><b>Nothing Scheduled</b>”;

days[35] = “January 31, 2005”;
msgs[35] = “&nbsp; &nbsp; <b>First Practice – Check the calendar</b>”;

var months = new Array(“”,
“January”, “February”, “March”, “April”, “May”, “June”,
“July”, “August”, “September”, “October”, “November”, “December”
);

var today = new Date(); // today
var mon = months[today.getMonth() + 1]; // month
var day = today.getDate()+1; // day
var year = y2k(today.getYear()); // year

function dateMsg() {
for (i = 0; i < days.length; i++) {
tempdate = new Date(days[i]);
tempmonth = months[tempdate.getMonth() + 1];
tempday = tempdate.getDate();
tempyear = y2k(tempdate.getYear());
if (year == tempyear && mon == tempmonth && day == tempday)
return(“<b>Today is ” + days[i] + “. ” + msgs[i]); // returns day message
}
return(“<b>Today is ” + mon + ” ” + day + “, ” + year + “.”); // returns default
}

// Y2K Fix Function
function y2k(year) {
if (year < 2000)
year = year + 1900;
return year;
}
// End –>
</script>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoSep 30.2005 — You have:

<i>
</i>var today = new Date(); // today
var mon = months[today.getMonth() + 1]; // month
var day = today.getDate()+1; // day
var year = y2k(today.getYear()); // year


"today.getDate()" only gives you a number, so anything you do to it is just using a number. If you do not wish to get September 31st then you have to put in an "if-statement" to make sure that if "today.getDate()+1" is 31 then your month changes to October and your day changes to the 1st.

Or you can do something like:

var Tomorrow=new Date(); //today

Tomorrow.setDate(Tomorrow.getDate() + 1) //tomorrow

Month = (Tomorrow.getMonth() + 1); //month

Day = Tomorrow.getDate(); //day

Year = Tomorrow.getFullYear(); //year
Copy linkTweet thisAlerts:
@felgallSep 30.2005 — ... Oops. Didn't see answer above.
×

Success!

Help @laplante spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...