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.youkuaiyun.com/iamduoluo/article/details/6673357
http://www.php100.com/html/webkaifa/database/Mysql/2013/0711/13641.html

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值