Viewed   56 times

I have got two arrows set up, click for next day, next two days, soon and previous day, two days ago, soon. the code seem not working? as it only get one next and previous day.

<a href="home.php?date=<?= date('Y-m-d', strtotime('-1 day', strtotime($date))) ?>" class="prev_day" title="Previous Day" ></a> 
<a href="home.php?date=<?= date('Y-m-d', strtotime('+1 day', strtotime($date))) ?>" class="next_day" title="Next Day" ></a>

is there a way if i click the next button, the date will continously change for the next day. for a moment it will only get one day ahead

 Answers

3
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.

Friday, December 9, 2022
4

you need to escape the a and t as both have special meaning when used as formatting options in date()

echo date('M j at h:i a');

See it in action

Monday, October 17, 2022
 
sgohl
 
3

You don't need to change the php.ini file if you use date_default_timezone_set(). Just set it to the timezone you will be working in.

Something like this should go in a config file or on the page where you're working with dates (if it is only one page):

date_default_timezone_set('America/Los_Angeles');
Friday, December 23, 2022
 
3

try it like this:

SELECT
  picture_id
FROM
  whatever
WHERE
  album_id = 23
AND
  picture_id > 3242
ORDER BY 
  picture_id
LIMIT 1
Monday, October 17, 2022
 
4

Perhaps two more queries would work ...

 select id,title from videos where id < $local_id order by id desc limit 1
 select id,title from videos where id > $local_id order by id asc limit 1
Friday, December 23, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :