mysql日期函式的使用

2021-07-15 06:38:59 字數 1126 閱讀 3601

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 = '******x'

第二種是使用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 = '******x'

mysql日期函式彙總 mysql日期函式彙總

一 當前時間獲取 1.now 獲得當前日期 時間 2.sysdate 獲得當前日期 時間 3.current timestamp,current timestamp 獲得當前時間戳 二 日期轉換函式 時間轉換函式 1.date format date,format time format time,...

mysql日期函式轉換 Mysql日期函式大全 轉

date add date,interval expr type date sub date,interval expr type adddate date,interval expr type subdate date,interval expr type 對日期時間進行加減法運算 adddate...

mysql日期函 MySQL 日期函式

mysql 日期函式 1,mysql dayofweek 和 weekday 獲取星期 在 mysql 中,我們可以用 dayofweek 和 weekday 函式獲取指定日期的星期.區別在於 dayofweek 獲取的星期索引是以 1 開始,而 weekday 獲取的星期索引是以 0 開始.day...