【发布时间】:2020-04-15 19:36:34
【问题描述】:
所以我想获取 $dob 的值并将其放入日期差异中以仅获取年份差异。下面的代码工作正常。但我的问题是当我尝试从 $POST 获取 $dob 时出现以下错误: Uncaught Exception DateTime:__construct();无法在位置 0 (1) 解析时间字符串 (27-12-2010):意外字符。
谁能告诉我如何解决这个问题,提前谢谢。
$dob = "27-12-2010";
$age = $dob;
$date = new DateTime($age);
$now = new DateTime();
$ageResult = $date->diff($now)->format("%y");
我想做什么:
$age = $_POST["age"];
$dob = $age;
$date = new DateTime($dob);
$now = new DateTime();
$ageResult = $date->diff($now)->format("%y");
and then put the $ageResult in the DB query
【问题讨论】:
标签: php date date-difference