0

I am using this code on the page to show when the next few dates are, they are always the next few days... but it is not working now:

<script>var now = new Date();
    var day = ("0" + (now.getDate()+3)).slice(-2);
    var day2 = ("0" + (now.getDate()+4)).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var today = (month)+"/"+(day)+"/"+now.getFullYear();
    var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
    document.write(today); document.write(' and/or ');document.write(today2);
</script>

But it is putting this out:

currently scheduled for: 05/32/2017 and/or 05/33/2017

how do I get the + 1 to have it go to the next month if it needs to?

Rich
  • 3
  • 4
  • Just create a date for each single date you want to prompt. – Zenoo May 29 '17 at 21:04
  • You're adding to a number instead of adding to a date. See, e.g., [Add days to JavaScript Date](https://stackoverflow.com/a/563442/1115360) for ideas. – Andrew Morton May 29 '17 at 21:05

1 Answers1

0

Try this

 <script>
var now = new Date();
    var day = ("0" + (now.setDate(now.getDate()+3)).getDate()).slice(-2);
    var day2 = ("0" + (now.setDate(now.getDate()+4)).getDate()).slice(-2);
    var month = ("0" + (now.setMonth(now.getMonth() + 1+1)).getMonth()).slice(-2);
    var today = (month)+"/"+(day)+"/"+now.getFullYear();
    var today2 = (month)+"/"+(day2)+"/"+now.getFullYear();
    document.write(today); document.write(' and/or ');document.write(today2);
</script>
Allen King
  • 2,372
  • 4
  • 34
  • 52