我有一个日期选择器,格式为:d/m/Y
.
我正在尝试以以下格式将日期从日期选择器发送到我的数据库:Y-m-d
.
我正在使用以下脚本:
$myDateTime1 = DateTime::createFromFormat('d/m/Y', $single_cal4);
$newSingle_cal4 = $myDateTime1->format('Y-m-d');
当我运行此脚本时,出现以下错误:
Fatal error: Call to a member function format() on a non-object in /send1.php on line 80
第 80 行是:
$newSingle_cal4 = $myDateTime1->format('Y-m-d');
我确信这个脚本适用于其他页面。有人知道为什么我会收到此错误以及如何修复它=
Alex Howansky 是对的,您应该$myDateTime1
通过执行以下操作来检查是否有效:
try {
$myDateTime1 = DateTime::createFromFormat('d/m/Y', $single_cal4);
} catch (Exception $e) {
echo $e->getMessage();
}
$newSingle_cal4 = $myDateTime1->format('Y-m-d');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句