我有一个连接表,在我想要与主表连接的表上有一个日期时间列名delivery_date_to
,我想将delivery_date_to
减去当前日期时间,减法结果将以天和小时格式(例如:2天23小时)作为记录。以下是我加入该表格的方式,
SELECT marketplace_orders.entity_id as id,
sales_order.delivery_date_to as delivery_date_to,
(deliver_date_to - current_time = xx days xx hour) as time_left
FROM marketplace_orders
INNER JOIN sales_order
ON sales_order.entity_id = marketplace_orders.order_id
AND sales_order.status IN ("pending","processing")
答案 0 :(得分:3)
试试这个解决方案:
SELECT
marketplace_orders.entity_id as id,
sales_order.delivery_date_to as delivery_date_to,
CONCAT(TIMESTAMPDIFF(Day,deliver_date_to,NOW()), ' days ',
MOD(TIMESTAMPDIFF(HOUR,deliver_date_to,NOW()),24), ' hour') as time_left
FROM marketplace_orders
INNER JOIN sales_order
ON sales_order.entity_id = marketplace_orders.order_id
AND sales_order.status IN ("pending","processing")
演示: