mysql日期函数的使用
2016-07-20 13:59
597 查看
mysql中想获取日期是当天的记录,由于日期存的是日期加时间。所以需要函数处理一下,这里有两种写法
第一种使用date() ,date()函数获取日期部分, 扔掉时间部分,然后与当前日期比较即可
第二种是使用DATE_FORMAT(字段, '时间格式')来转化
第一种使用date() ,date()函数获取日期部分, 扔掉时间部分,然后与当前日期比较即可
SELECT as_ff_vote_record.id as as_ff_vote_record_id, as_ff_vote_record.anchor_id as as_ff_vote_record_anchor_id, as_ff_vote_record.phone as as_ff_vote_record_phone, as_ff_vote_record.vote_time as as_ff_vote_record_vote_time FROM ff_vote_record as_ff_vote_record WHERE date(as_ff_vote_record.vote_time) = CURDATE() and phone = 'xxxxxxx'
第二种是使用DATE_FORMAT(字段, '时间格式')来转化
SELECT as_ff_vote_record.id as as_ff_vote_record_id, as_ff_vote_record.anchor_id as as_ff_vote_record_anchor_id, as_ff_vote_record.phone as as_ff_vote_record_phone, as_ff_vote_record.vote_time as as_ff_vote_record_vote_time FROM ff_vote_record as_ff_vote_record WHERE DATE_FORMAT(as_ff_vote_record.vote_time, '%Y-%m-%d') = CURDATE() and phone = 'xxxxxxx'
相关文章推荐
- mysql explain用法
- 交叉编译mysql客户端libmysql
- mysql 创建临时节点
- MySQL生产库主从重新同步操作注意事项
- mysql 不允许连接
- mysql 创建临时节点
- mysql 创建临时节点
- 修改mysql密码
- mysql中FIND_IN_SET的使用方法
- Mysql的存储过程,Mybatis对存储过程的调用
- mysql5.7.13-windows 免安装版配置简介
- MySql LIKE 查找带反斜线“\”的记录
- 安装mysql.so
- mysql 父类子类查询
- mysql存储引擎概述
- 导mysql数据,遇到 longtext 类型,navicat导出会出现乱码
- Mysql用户管理及权限设置
- Mysql:四种常用的MySQL建表语句
- mysql 里面的isnull()和ifnull() is null 和 is not null
- message from server: "Host 'XXX' is not allowed to connect to this MySQL server