MySQL:使用1970年以前的日期 [英] MySQL: Working with dates before 1970
问题描述
我正在一个教会网站上工作,在 1970
之前有许多事件,这些事件从 1001
开始今天,我如何在 MySQL
中存储日期?
I'm working on a church site wich has many events before 1970
, these events starts from 1001
to today, how can I store the dates in MySQL
?
$y = $_REQUEST["year"];
$m = $_REQUEST["month"];
$d = $_REQUEST["day"];
$date = date("Y-m-d", "$y/$m/$d");
只有在 1970之后的日期才能正常工作
,如何在今年之前存储日期?
This works fine only for dates after 1970
, how can I store dates before this year?
在 MySQL
中应该有什么样的数据类型?现在我将列设置为 date
type
What kind of datatype should I have in MySQL
? Now I've set my column to date
type
推荐答案
DATE
没问题。它可以将值从1000到9999 AD 存储
DATE
is fine. It can store values from 1000 to 9999 AD.
当您只需要一个日期值,而没有时间部分时,将使用DATE类型。 MySQL以YYYY-MM-DD格式检索并显示DATE值。支持的范围是'1000-01-01'到'9999-12-31'。
The DATE type is used when you need only a date value, without a time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.
与PHP的旧式不同日期功能( date()
, strtotime()
....)这些工作与UNIX时间戳,当使用32位值限制在从1970到2038之间的日期范围。
It's different with PHP's old-style date functions (date()
, strtotime()
....) these work with UNIX timestamps and, when using 32-bit values, are limited to a date range from 1970 to 2038.
要处理超过此值的日期值,请使用PHP 5的新的面向对象 DateTime
class 。
To work with date values beyond that, work with PHP 5's new object-oriented DateTime
class.
这篇关于MySQL:使用1970年以前的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!