现在的位置: 首页 > 数据库 > 正文

mysql日期比较语句

2020年05月02日 数据库 ⁄ 共 793字 ⁄ 字号 评论关闭

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);
  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
  MySql中时间比较的实现
  unix_timestamp 函数可以接受一个参数,也可以不使用参数。它的返回值是一个无符号的整数。不使用参数,它返回自1970年1月1日0时0分0秒到现在所经过的秒数,如果 使用参数,参数的类型为时间类型或者时间类型的字符串表示,则是从1970-01-01 00:00:00到指定时间所经历的秒数。
  有了这个函数,就可以很自然地把时间比较转换为一个无符号整数的比较。
  例如,判断一个时间是否在一个区间内
  unix_timestamp( time ) between unix_timestamp( 'start ') and unix_timestamp( 'end' )

抱歉!评论已关闭.