我有:
PHP代码:$date = date("F j, Y, g:i a");
并将其发送到我的数据库
我使用
$date = $gg['date'];
从我的数据库获取日期当我echo $date
时 -> June 30, 2012, 3:45 pm
时间已经在数据库中设置了邮件.php,并且在订单跟踪中.php我正在获得时间,并希望增加一周的时间。
所以我想添加一个星期:$date = $gg['date'];
$connection = mysql_connect("localhost","root","") or die ("Can't connect");
mysql_select_db("shoppingcart", $connection) or die ("Can't connect");
$ordertracking = mysql_query("SELECT * FROM `ordertracking` WHERE orderid='$orderid'");
while($gg=mysql_fetch_array($ordertracking))
{
$progress = $gg['progress'];
$date = $gg['date'];
}
mysql_close($connection)
使用 DateTime
modify()
方法
$dt = DateTime::createFromFormat("F j, Y, g:i a", $date);
$dt->modify('+1 week');
echo $dt->format("F j, Y, g:i a");
这里有一些简单的解决方案)
$date = date( 'F j, Y, g:i a' );
echo date( 'F j, Y, g:i a', strtotime( $date ) + 7 * 24 * 60 * 60 );
你能试试这个吗:
$date = 'June 30, 2012, 3:45 pm';
$new_date = date("F j, Y, g:i a",strtotime(date("F j, Y, g:i a", strtotime($date)) . " +1 week"));
希望这有帮助。
如果你想使用 strtotime 方法,你会做
$date = date('F j, Y, g:i a', strtotime('2012-06-30 3:45 pm +1 week'));