Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 794
vitto Avatar asked Dec 16 '10 23:12

vitto


1 Answers

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.

like image 119
Pekka Avatar answered Sep 27 '22 22:09

Pekka