MySQL:1970年之前的日期 [英] MySQL: dates before 1970

查看:277
本文介绍了MySQL:1970年之前的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个教堂站点上工作,该教堂在1970之前有很多事件,这些事件从1001开始到今天,如何将日期存储在MySQL中?

I'm working on a church site which 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类型

What kind of datatype should I have in MySQL? Now I've set my column to date type

推荐答案

DATE很好.它可以存储值从公元1000到9999 .

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的新的面向对象的.

To work with date values beyond that, work with PHP 5's new object-oriented DateTime class.

这篇关于MySQL:1970年之前的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆