0

I have a variable with the current date that has been imported from PHP. "5122016". On the click of a button I need this variable to increase (5132016, 5142016, 5162016) etc and eventually the month and year change with it too. How can I do this? Thank you!

<?php
$dateName = date("mdY");
?>

<script>
    $(document).on("click", "#day-right", function(event) {
        var Date = <?php echo $dateName ?>;
        //var Date increases by one day
    });
</script>
Ben L
  • 127
  • 1
  • 1
  • 13
  • While this has a javascript tag, it seems to be a PHP question. For incrementing dates in javascript, this is a duplicate of [*Incrementing a date in JavaScript*](http://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript). For PHP it's probably a duplicate of [*Simplest way to increment a date in PHP?*](http://stackoverflow.com/questions/660501/simplest-way-to-increment-a-date-in-php). – RobG May 12 '16 at 05:49
  • Don't use `Date` as your var name, [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) is already a built-in object in JS. JS variable names are case-sensitive, so you could use `date` instead. – Useless Code May 13 '16 at 13:15

3 Answers3

0

you can use the follow to add n days:

myDate.setDate(myDate.getDate() + n);
// to add just one day
myDate.setDate(myDate.getDate() + 1);
Sergey
  • 5,208
  • 25
  • 36
0
<?php $date = date("mdY", strtotime("+1 day")); ?>
w3core
  • 129
  • 3
0

In this one day added to the current date

$dateName  = date("m-d-Y", time() + 86400);
Nandhakumar
  • 92
  • 1
  • 2
  • 12