您的位置:首页 > 数据库 > MySQL

mysql日期函数的使用

2016-07-20 13:59 597 查看
mysql中想获取日期是当天的记录,由于日期存的是日期加时间。所以需要函数处理一下,这里有两种写法

第一种使用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'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: