用php获得下一个和前一天 [英] get next and previous day with php

查看:72
本文介绍了用php获得下一个和前一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ive有2个箭头设置,点击次日,接下来的2天,即将到前一天,2天前,很快。代码似乎不工作?因为它只得到下一个和前一天的一个。

 < a href =home.php?date =<?= date('Ym-d',strtotime(' -  1 day',strtotime($ date)))> class =prev_daytitle =上一天>< / a> 
< a href =home.php?date =<?= date('Y-m-d',strtotime('+ 1 day',strtotime($ date)))> class =next_daytitle =Next Day>< / a>

有一种方法,如果我点击下一个按钮,日期将不断变化为第二天。一会儿只会得到1天的时间。

解决方案

  date('Ym-d ',strtotime('+ 1天',strtotime($ date))

应该读



  date('Ym-d',strtotime('+1 day')






更新以回覆问题,在评论中不断更改日期。

 <?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;?>>上一个< / a>
< a href =?date =<?= $ next_date;?>> Next< / a>

这将从当时开始的日期增加和减少一个。 p>

ive got 2 arrows set up, click for next day, next 2 days, soon and previous day, 2 days ago, soon. the code seem not working? as it only get 1 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 1 day ahead

解决方案

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.

这篇关于用php获得下一个和前一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆