Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

php - MySQL: dates before 1970

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");

This works fine only for dates after 1970, how can I store dates before this year?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

DATE is fine. It can store values from 1000 to 9999 AD.

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'.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...