使用MM / DD / YYY转换为日期时间时,日期与日期中的日期一起排序

时间:2013-02-06 10:40:55

标签: mysql sql

日期时间转换存在问题,目前“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

1 个答案:

答案 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