mysql - 使用 MM/DD/YYY 在转换到日期时的日期为varchar的日期排序日期

  显示原文与译文双语对照的内容
0 0

日期转换的问题当前"xl_date"有日期 MM/DD/YYYY

示例查询:-

SELECT orders.*, 
 customer.id AS userid, 
 customer.login, 
 convert(datetime, orders.xl_date, 101) as ddates 
FROM orders 
LEFT JOIN customer 
ON orders.userid = customers.id 
WHERE 1 
ORDER BY ddates DESC LIMIT 0, 30
时间:原作者:2个回答

0 0

你需要使用 STR_TO_DATE 函数。 例如-

SELECT STR_TO_DATE(orders.xl_date, '%m/%d/%Y') AS as ddates FROM orders

你的查询是-

SELECT
 orders.*, 
 customer.id AS userid, 
 customer.login, 
 STR_TO_DATE(orders.xl_date, '%m/%d/%Y')as ddates 
FROM orders 
 LEFT JOIN customer 
 ON orders.userid = customers.id 
WHERE
 1 
ORDER BY
 ddates DESC
LIMIT 0, 30
原作者:
...