mysql日期比较
2013-09-12 15:44
232 查看
mysql日期比较语句
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
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' )
函数:FROM_UNIXTIME
作用:将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示。
语法:FROM_UNIXTIME(unix_timestamp,format)
SELECT *,FROM_UNIXTIME(created, '%Y-%m-%d') as riqi FROM `rc_ms_users`
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
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' )
函数:FROM_UNIXTIME
作用:将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示。
语法:FROM_UNIXTIME(unix_timestamp,format)
SELECT FROM_UNIXTIME(1234567890, '%Y-%m-%d %H:%i:%S')
SELECT *,FROM_UNIXTIME(created, '%Y-%m-%d') as riqi FROM `rc_ms_users`
相关文章推荐
- mysql varchar类型转换日期类型,比较大小
- Mysql日期类型大小比较---拉取给定时间段的记录
- mysql的日期存储字段比较int,datetime,timestamp区别
- mybatis mysql 日期比较
- mysql与oracle 比较日期
- mysql 日期比较及日期函数用法
- mysql日期比较语句
- mysql 日期比较
- MySQL日期比较
- PHP以及MYSQL日期比较方法
- mysql 日期转换 比较
- mysql日期比较
- Mysql日期类型大小比较
- Mysql日期类型大小比较---拉取给定时间段的记录
- MySQL中日期比较时遇到的编码问题解决办法
- 【Mysql】关于任意日期的比较
- mysql日期类型比较
- mysql中日期比较大小方法详解
- MySql日期比较
- mysql日期比较小小总结