$curdate = 2015-13-03 12:06:03
使用此$curdate
如何在今天或昨天或前一天或前两天计算此日期等等。在php中
答案 0 :(得分:1)
在PHP中有一个名为strtotime()的函数: http://php.net/manual/en/function.strtotime.php
这应该是你要搜索的内容。
答案 1 :(得分:0)
你可以使用strtotime。
实施例
$curdate = strtotime("2015-13-03 12:06:03");
$newdate = strtotime("+1 day",$curdate);
答案 2 :(得分:0)
我的方法是这样做:
$date = new DateTime('2000-12-31 12:06:03');
$date->modify('-1 day');
echo $date->format('Y-m-d H:i:s') . "\n";
但有多条道路可供使用。
答案 3 :(得分:0)
你不能只是在字符串中指定时间来创建日期变量..结帐这个..
$curdate = date("Y-m-d H:i:s",mktime(12,06,03,03,13,2015));
$yesterday = date('Y-m-d H:i:s', strtotime('-1 day', strtotime($curdate)));
$twodaysbefore = date('Y-m-d H:i:s', strtotime('-2 day', strtotime($curdate)));
echo "yesterday: " . $yesterday."-- 2 day before :".$twodaysbefore;