这是我的代码:
SELECT *
FROM `products`
WHERE
DATE_ADD( UTC_TIMESTAMP( ) , INTERVAL 7 HOUR )
BETWEEN DATE_SUB( STR_TO_DATE( IsPromotionDate, '%m/%d/%Y %H:%i' ) , INTERVAL 3 DAY )
AND STR_TO_DATE( IsPromotionDate, '%m/%d/%Y %H:%i' )
但结果会返回IsPromotionDate之前的所有产品,但不会返回IsPromotionDate之后的所有产品 - 3.我仍然没有弄清楚原因。
答案 0 :(得分:1)
试试这个:
SELECT * FROM `products`
WHERE DATE_ADD(UTC_TIMESTAMP( ), INTERVAL 7 HOUR) BETWEEN DATE_SUB(IsPromotionDate, INTERVAL 3 DAY) AND IsPromotionDate
或强>
SELECT * FROM `products`
WHERE DATEDIFF(DATE_ADD(UTC_TIMESTAMP(), INTERVAL 7 HOUR), IsPromotionDate) BETWEEN 0 AND 3
答案 1 :(得分:1)
SELECT *
FROM `products`
WHERE
STR_TO_DATE( IsPromotionDate, '%m/%d/%Y %H:%i')
BETWEEN NOW()
AND DATE_SUB( now() , INTERVAL 3 DAY )