php - 无法将数据库值 "1876-01-01 00:00:00-00:00:00"转换为 Doctrine 类型日期时间

标签 php postgresql datetime doctrine-orm

为什么 Doctrine 不喜欢旧日期?

Exception was thrown : Could not convert database value "1876-01-01 00:00:00-00:00:00" to Doctrine Type datetime

还有一个:

Exception was thrown : Could not convert database value "0000-00-00 00:00:00-00:00:00" to Doctrine Type datetime

在我的实体中,我确实覆盖了 datetimedatetimetz

Type::overrideType('datetime', 'Doctrine\DBAL\Types\VarDateTimeType');
Type::overrideType('datetimetz', 'Doctrine\DBAL\Types\VarDateTimeType');

如果我将日期更新为 1976-01-01 00:00:00-00:00:00,它工作正常。

更新:

所以我正在运行 Ubuntu 12.04 64 位,我也知道我有 64 位 time_t 从这些测试中工作:

strtotime() produces different output on 32 and 64 bit systems running PHP 5.3.3 (as mentioned previously). This affects the "zero date" ("0000-00-00 00:00:00") as well as dates outside the traditional 32 date range.

测试:

strtotime("0000-00-00 00:00:00") returns FALSE on a 32 bit system.
strtotime("0000-00-00 00:00:00") returns -62169955200 on a 64 bit system.

当执行 echo strtotime("0000-00-00 00:00:00"); 时,我明白了:

php time_test.php -62169966000

那么 Doctrine 有问题吗?

最佳答案

PHP 中的纪元是 1970 或 1901,具体取决于您的系统。

来自 PHP 手册:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).

http://php.net/manual/en/function.date.php

关于php - 无法将数据库值 "1876-01-01 00:00:00-00:00:00"转换为 Doctrine 类型日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14708763/

相关文章:

php - 如何在php中将字符串转换为RAW(Oracle)?

php - 我应该如何在 Wordpress 中将准备好的语句与查询中的变量一起使用?

sql - Elixir PostgreSQL - 选择查询返回不符合 WHERE 子句的结果

postgresql - Postgres 的全文搜索什么时候支持词组匹配和邻近匹配?

c++ - 仅将纪元字符串保存到 mysql 日期时间年/月/日但没有小时分钟秒

python - 如何在特定日期之后删除数据集中的值?

php - Eloquent groupBy 在 Laravel 5.3 中使用有效的 SQL 查询生成 "SQLSTATE[42000]"

php - 如何解决magento1.9.1.0这个错误

python - Pandas - 从日期时间中提取日期,如果时间超过某个小时则加一天

sql - SQL 规范是否提供了一种更好的方法来对两个集合进行异或运算?