我在按日期排序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
但是似乎不起作用...
我如何才能按日期和时间订购?
最佳答案
假设您的DateAndHour列是一个字符串,可能是您需要适当的转换
SELECT PlayerSteamID
, BanLength
, BanReason
, AdminName
, AdminSteamID
, PlayerName
, MapName
, DateAndHour
FROM BansList
ORDER BY str_to_date(DateAndHour, '%T - %d/%m/%Y') DESC