将日期字符串注入为 SRTOTIME


inject date string as srtotime

我正在尝试从几个小时开始解决这个问题,我尝试了网站内提供的不同解决方案,但由于某些原因,网站在应用建议时总是返回错误。

我有一个使用日期选择器的表单字段,输出是格式的日期:十一月 6th, 2013

现在,mysql 数据库和脚本的其余部分仅适用于十位数日期格式,我被告知这是 unix 时间戳格式,可以使用 strtotime 进行转换。所以我正在尝试将字符串转换为 strtotime,但无法解决这个问题。现在我有:

    $insertData['enddate']  = $this->input->post('openDays');

返回日期"2013 年 11 月 6 日",我将其更改为

  $insertData['enddate'] = strtotime $this->input->post('openDays');
返回错误:

解析错误:语法错误,第 214 行/home/xxx/public_html/app/controllers/project.php 中的意外T_VARIABLE

关于如何正确应用它的任何建议?

谢谢

试试这个,你使用 strtotime 犯了一个错误。

$insertData['enddate'] = strtotime($this->input->post('openDays'));

参考链接: Strtotime PHP

strtotime是一个函数,所以你需要像这样括起来(使用括号)

$insertData['enddate'] = strtotime($this->input->post('openDays'));
                           -------^                       -------^  

编辑:

我建议你使用DateTime而不是strtotime

$dt = DateTime::createFromFormat('H:i', '17:00');
$insertData['enddate']=$dt->format('H:i');