Ad Code

get next and previous day with PHP

date('Y-m-d', strtotime('+1 day', strtotime($date))) 
Should read
date('Y-m-d', strtotime(' +1 day'))
 
Update to answer question asked in comment about continuously changing the date.
<?php
$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');
$prev_date = date('Y-m-d', strtotime($date .' -1 day')); 
$next_date = date('Y-m-d', strtotime($date .' +1 day'));
?>

<a href="?date=<?=$prev_date;?>">Previous</a> 
<a href="?date=<?=$next_date;?>">Next</a>
 
This will increase and decrease the date by one from the date you are on at the time.
 

Post a Comment

0 Comments