我想添加日期中的周数。结果应在日期"Y-m-d"内。
这里,"time_take"来自数据库,这是第1、2、3、5、7等。
<?php
$date = $record['Child']['dob'];
$str = "'+".$Vac['Vac']['time_take']." week'";
echo date('Y-m-d',strtotime($str,strtotime($date)));
?>
我的成绩是"1970-01-01"
这是数据库中日期的格式。
帮帮我。
<?php
$date = "2015-01-01";
$str = "+".$Vac['Vac']['time_take']." week";
//echo date('Y-m-d',strtotime("$str",strtotime($date)));
echo date('Y-m-d',strtotime($str,strtotime($date)));
?>
输出:
2015-01-08
登录在线编辑器。单击此处
如果你一开始就很简单,你总是可以在工作后连接代码
$dob = $record['Child']['dob'];
$num = $Vac['Vac']['time_take'];
$pDate = strtotime("$dob + $num week");
echo date('Y-m-d',$pDate);
试试这个
$start_date = $record['Child']['dob'];
$str = $Vac['Vac']['time_take'];
$date = strtotime($start_date);
$date = strtotime("+".$str." week", $date);
echo date('Y-m-d', $date);
在我的代码中进行了一些更正后,得到了2-3个答案的帮助。最终答案是:-
<?php
$date = $record['Child']['dob'];
$str = "+".$Vac['Vac']['time_take']." week";
echo date('Y-m-d',strtotime($str,strtotime($date)));
?>
输出正确。
它在连接代码后工作一次。
$start_date = $record['Child']['dob'];
$str = $Vac['Vac']['time_take']." week";
$date = strtotime($start_date);
$date = strtotime("+".$str." week", $date);
echo date('Y-m-d', $date);
输出:
2015-01-08