为日期分配变量
我需要为今天的日期分配一个特定的数字,例如 1559,并根据此计算前一天和后几天。例如,2天前是1557,昨天是1558,今天是1559,明天是1560,等等。这样,我将使用post方法创建一个分页。我的日期采用 YYYY-MM-DD 格式并存储在 mySQL 中的日期变量中。我应该如何将数字分配给日期并相应地计算日期?
顺便说一句,我的代码看起来像这样:
include ('connect.php');
date_default_timezone_set("Etc/GMT+7");
$timestamp= date("Y-m-d");
$day1=1357;
echo ('<form action="total_inf.php" method="post" name="inf_day">');
for($i=0;$i<10;$i++)
{
$newdate=strtotime('-$i days',strtotime($timestamp));
$newdate = date ( 'Y-m-d' , $newdate );
$prevdays=$day1-$i;
print ('<input type="submit" name="bugun" value="'.$prevdays.'"> ');
}
echo ('</form>');
$day_selected=$_POST[bugun];
$sql1="SELECT * FROM userdata WHERE zaman='$timestamp'";
$result1=mysql_query($sql1,$conn);
I need to assign a specific number like 1559 to today's date and calculate the previous and next days according to this. For example 2 days ago is 1557, yesterday is 1558, today is 1559 tomorrow is 1560, etc. With that, i will create a pagination for the days with post method. My date is in YYYY-MM-DD format and stored in a date variable in mySQL. What should I do to assing numbers to dates and calculate the dates accordingly?
my code looks like this btw:
include ('connect.php');
date_default_timezone_set("Etc/GMT+7");
$timestamp= date("Y-m-d");
$day1=1357;
echo ('<form action="total_inf.php" method="post" name="inf_day">');
for($i=0;$i<10;$i++)
{
$newdate=strtotime('-$i days',strtotime($timestamp));
$newdate = date ( 'Y-m-d' , $newdate );
$prevdays=$day1-$i;
print ('<input type="submit" name="bugun" value="'.$prevdays.'"> ');
}
echo ('</form>');
$day_selected=$_POST[bugun];
$sql1="SELECT * FROM userdata WHERE zaman='$timestamp'";
$result1=mysql_query($sql1,$conn);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅日期时间参考
更新:
适用于 PHP >= 5.3.0。请参阅 DateInterval::format
See DateTime reference
UPDATE:
Works with PHP >= 5.3.0. See DateInterval::format