Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...