我在按日期订购mysql结果时遇到问题。日期的格式如下:15:24:57-21/04/2019(24小时制)
我已经尝试过了:
SELECT PlayerSteamID, BanLength, BanReason, AdminName, AdminSteamID, PlayerName, MapName, DateAndHour FROM BansList ORDER BY DateAndHour DESC
还有这个
SELECT PlayerSteamID, BanLength, BanReason, AdminName, AdminSteamID, PlayerName, MapName, DateAndHour FROM BansList ORDER BY UNIX_TIMESTAMP(STR_TO_DATE(DateAndHour, '%h:%i:%s - %d/%m/%Y')) DESC
但似乎不起作用...
我如何才能按日期和时间排序?
答案 0 :(得分:0)
假设您的DateAndHour列是一个字符串,可能需要适当的转换
SELECT PlayerSteamID
, BanLength
, BanReason
, AdminName
, AdminSteamID
, PlayerName
, MapName
, DateAndHour
FROM BansList
ORDER BY str_to_date(DateAndHour, '%T - %d/%m/%Y') DESC