简体   繁体   English

date('c') 仅作为数据保存在 MySQL 中

[英]date('c') only being saved as data in MySQL

The date is being truncated or not used to update my MySQL table.日期被截断或未用于更新我的 MySQL 表。

Generating the date in PHP 7:在 PHP 7 中生成日期:

$date = date('c');
$modelImportState->setImportCompletedTime($date);

try {
  $modelImportState->save();
  return true;
}
catch(\Exception $e){
    ....
}

This generates the data and time correctly but in the DM only the time is saved (field is DATETIME).这将正确生成数据和时间,但在 DM 中仅保存时间(字段为 DATETIME)。

没有时间的日期图像

表结构

Update:更新:

The $modelImportState is a model from the Magento Framework (sorry, as the saving is working I thought that wasn't relevant). $modelImportState 是 Magento 框架中的一个模型(抱歉,因为保存正在起作用,我认为这无关紧要)。 It is now fixed, it was because for some reason the column wasn't actually updated to Datetime when I changed it before.现在已修复,这是因为由于某种原因,当我之前更改该列时,该列实际上并未更新为 Datetime。

试试这个 $date = date('Ymd H:i:s');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM