0

Hi Everyone and thanks in advance for the help. I'm having an issue with getting my Javascript date code to advance from the current date to tomorrow's date. I've searched here in previous posts but the answers don't seem to be working.

<SCRIPT LANGUAGE="JavaScript">
// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;
                            }

// Join it all together
today =  days[now.getDay()] + ", " +
     months[now.getMonth()] + " " +
     date + ", " +
     (fourdigits(now.getYear())) ;
</script>

Where would the + 1 be inserted in order to make the date tomorrow's date?

Jimbajim
  • 3
  • 3

1 Answers1

1
now.setDate(now.getDate() + daysToAdd); 

should do the trick. It's not even jQuery, just Javascript. If you're getting the 1 added to the end of the string make sure now is still being treated as a Date and hasn't been reassigned somewhere to a different type.

It shouldn't matter whether daysToAdd is a literal or a variable, either. Both should work.

More specifically, this should work:

<SCRIPT LANGUAGE="JavaScript">
// Get today's current date.
var now = new Date();
now.setDate(now.getDate() + 1);

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;
                            }

// Join it all together
today =  days[now.getDay()] + ", " +
     months[now.getMonth()] + " " +
     date + ", " +
     (fourdigits(now.getYear())) ;
</script>
Skerkles
  • 1,123
  • 7
  • 15