mysql关于日期的查询


一 、关于日期查询条件用字段timestamp

      A、利用date_format

       date_format('timestamp','%Y%m%d')>'20140101'

DATE_FORMAT(` timestamp `, '%Y-%m-%d %H:%i:%s' )>= '2013-03-05 00:00:00'

 

mysql> select * from organizationtest where date_format(created,'%Y%m%d') betwee

n '20140101' and '20140101000000';

 

select date_format(created,'%Y%m%d') from organizationtest where date_format(created,'%Y%m%d') betwee

n '20140101' and '20140101000000';

 

 select date_format(created,'%Y%m%d') from organization where date_format(created,'%Y%m%d') < '201405101' 

    ->'20140506 ;

        B、利用Date

          DATE('timestamp')='2014-01-01'

 

 

二 、关于日期查询条件用字段int

     用unix_timestamp('2010-04-01')时间戳,存到字段中,

     用FROM_UNIXTIME( 1249488000, '%Y%m%d' )  到到时间进行显示

 

       相关查询操作参见:

http://blog.csdn.net/iamduoluo/article/details/6673357
http://www.php100.com/html/webkaifa/database/Mysql/2013/0711/13641.html

 

猜你喜欢

转载自qinshiqi.iteye.com/blog/2062139