mysql date comparison statement
select * from student where '2012-02-27 00:00:00' < created_date and '2012-02-29 00:00:00' > created_date
select * from student where UNIX_TIMESTAMP('2012-02-27 00:00:00') < UNIX_TIMESTAMP(created_date) and UNIX_TIMESTAMP('2012-02-29 00:00:00') > UNIX_TIMESTAMP(created_date);
www.2cto.com
SELECT * FROM student WHERE (UNIX_TIMESTAMP(created_date) - UNIX_TIMESTAMP('2012-02-26 00:00:00') ) >= 0 AND (UNIX_TIMESTAMP(created_date) - UNIX_TIMESTAMP('2012-02-29 00:00:00') ) <= 0
Implementation of Time Comparison in MySql
The unix_timestamp function can take one argument or no arguments. Its return value is an unsigned integer. Without parameters, it returns the number of seconds elapsed since January 1, 1970 0:00:00 seconds. If parameters are used, the type of the parameter is a time type or a string representation of a time type, which is from 1970- The number of seconds elapsed since 01-01 00:00:00 to the specified time.
With this function, it is natural to convert a time comparison to an unsigned integer comparison.
For example, to determine whether a time is within an interval
unix_timestamp( time ) between unix_timestamp( 'start ') and unix_timestamp( 'end' )
Multi-condition judgment in mysql:
The date is required to be on 2017-12-28, and the value of the city column is Beijing. The SQL statement is as follows:
SELECT * FROM table_name where UNIX_TIMESTAMP(flightDate)=UNIX_TIMESTAMP('2017-12-28') and city='Beijing';