通過時間字串排序,發現:"3日"比"31日"靠前
因為comment_time欄位是字元型,字串排序從左到右, "日" 比 "1" 大,所以就是上圖那種排序
把時間字串格式化即可,使用函式:str_to_date(str, format)
str_to_date( `comment_time`,'%y年%m月%d日')
格式化時間字串並按時間排序:
select * from qx_monitoring_comment where attraction_id = 1 order by str_to_date( `comment_time`,'%y年%m月%d日') desc;
sql server日期時間轉字串
一 sql server日期時間函式 sql server中的日期與時間函式 1.當前系統日期 時間 select getdate 2.dateadd 在向指定日期加上一段時間的基礎上,返回新的 datetime 值 例如 向日期加上2天 select dateadd day,2,2004 10 1...
sql server日期時間轉字串
一 sql server日期時間函式 sql server中的日期與時間函式 1.當前系統日期 時間 selectgetdate 2.dateadd在向指定日期加上一段時間的基礎上,返回新的 datetime值 例如 向日期加上2天 selectdateadd day,2,2004 10 15 返回...
sql server日期時間轉字串
一 sql server日期時間函式 sql server中的日期與時間函式 1.當前系統日期 時間 selectgetdate 2.dateadd在向指定日期加上一段時間的基礎上,返回新的 datetime值 例如 向日期加上2天 selectdateadd day,2,2004 10 15 返回...