Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and MySQL smallest and largest possible date

Tags:

date

php

mysql

What is the largest date PHP and MySQL recognizes?

I mean, I have different values for different timeline and I want to make them all as BETWEEN selects in MySQL, like this:

SELECT * FROM table WHERE date BETWEEN '2011-10-01' AND '2011-10-02';
SELECT * FROM table WHERE date BETWEEN '2011-10-03' AND '2011-10-10';

etc.

To get all options, was thinking of something like this:

SELECT * FROM table WHERE date BETWEEN '0000-01-01' AND '2011-10-01';
SELECT * FROM table WHERE date BETWEEN '2011-10-02' AND '2011-10-10';
SELECT * FROM table WHERE date BETWEEN '2011-10-11' AND '9999-12-31';

Will this always work or is there a chance the code might break at some point?

like image 940
Peon Avatar asked Nov 01 '12 14:11

Peon


People also ask

What is the minimum date in MySQL?

DateTime. MinValue is 0001-01-01 00:00:00 , but the minimum supported value for a DATETIME column is 1000-01-01 00:00:00 . In many versions of MySQL Server, you can successfully insert this value; however, it is not officially supported. By default, inserting DateTime.

What is date value length MySQL?

MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.


2 Answers

Here is the different date range , depends on your column type:

As per docs

The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

like image 96
metalfight - user868766 Avatar answered Sep 22 '22 15:09

metalfight - user868766


The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.

taken from http://dev.mysql.com/doc/refman/5.5/en/datetime.html

like image 28
jtheman Avatar answered Sep 18 '22 15:09

jtheman