PHP and MySQL smallest and largest possible date

后端 未结 6 539
挽巷
挽巷 2021-01-18 06:42

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

相关标签:
6条回答
  • 2021-01-18 06:51

    Maybe get the max and min values from your table first:

    SELECT * FROM table WHERE date BETWEEN (SELECT MIN(date) FROM table) AND (SELECT MAX(date) FROM table)
    
    0 讨论(0)
  • 2021-01-18 06:53

    MySQL's DATETIME type supports from "1000-01-01" to "9999-12-31". That should be sufficient.

    PHP can analyze those as well; they aren't two digit years, so it's good. I just ran strtotime on 9999-01-01 and it worked.

    0 讨论(0)
  • 2021-01-18 07:01

    Dates are nothing more than integers. Integer size are system dependent; i.e. 32 bit, 64 bit, etc.

    In php integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX

    In mysql you can do something lke this: SELECT ~0 as max_bigint_unsigned

    0 讨论(0)
  • 2021-01-18 07:02

    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

    0 讨论(0)
  • 2021-01-18 07:06

    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.

    0 讨论(0)
  • 2021-01-18 07:15

    Could you do it like this:

    SELECT * FROM table WHERE date < '2011-10-01';
    SELECT * FROM table WHERE date BETWEEN '2011-10-02' AND '2011-10-10';
    SELECT * FROM table WHERE date > '2011-10-11' 
    
    0 讨论(0)
提交回复
热议问题