mysql數據庫日期是varchar類型的時間比較查詢


 單純的字符串比較結果不精確.

select * from 表明 where times> '2088/12/8 10:02:40' (×)


轉換函數如下(數據庫為varchar):

select * from h_hotelcontext where now() between STR_TO_DATE(Start_time,'%Y-%m-%d %H:%i:%s') and STR_TO_DATE(End_time,'%Y-%m-%d %H:%i:%s');

select max(addtime) from student  where stuid='9';(×)



 select max(STR_TO_DATE( addtime,'%Y/%m/%d %H:%i:%s')) from student where stuid='9';

有些時候%Y-%m-%d %H:%i:%s  這種轉換格式並不能得到正確的結果,原因待查


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM