Display month & last sunday of month. Help with my code
Here's what I have so far. I'm getting closer. I can write the date of last sunday of the month but I can't seem to get the current month to display properly.
Example: for this month I want the code to display January 27 but I'm getting December 27. 27 IS the correct date because 27 is the last Sunday in this month but (obviously) I need it to display January because Januuary IS the current month.
Yes, that will do it. Thanks lucky. I was hoping to combine the two bits of code into one script. IE Display current month AND the date of the last Sunday (27) in the current month. Having it in one piece of code will not really be necessary. This will do just fine.
document.write("<h1>Lucky is a rockstar!</h1>");
var monthNames = [ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" ];
var today = new Date(); // or any specified date
var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);
var dy = lastDayOfMonth.getDay();
var dt = lastDayOfMonth.getDate();
var date = dt-dy;
var suffix = (date==1 || date==21 || date==31) ? "st" : "th" && (date==2 || date==22) ? "nd" : "th" && (date==3 || date==23) ? "rd" : "th";
var result = monthNames[today.getMonth()] + " " + date + suffix;
alert ("The last Sunday of the month is " + result);
Quizmaster: What was the currency of Holland before the Euro?
Contestant: Was it the Danish Krone?
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Well if that God Save the Queen is Johnny & Sid's version I know that one too! Thanks for all your help. Got me out of a perplexing issue. document.write obsolete? Oh brother ... it's working for my purposes in this instance so I will not temp fate at this time. Cheers.
document.write obsolete? Oh brother ... it's working for my purposes in this instance so I will not temp fate at this time. Cheers.