在我的数据库中,对象以创建日期保存,格式为dd-month-year hours:seconds(示例2011-12-07 09:59:41
)。我应该用什么sql命令来获取2012年4月之后创建的对象?
答案 0 :(得分:2)
-- After April 1st, including
SELECT *
FROM mytable
WHERE creationDate >= CAST('2012-04-01' AS DATE)
-- After April 1st, excluding
SELECT *
FROM mytable
WHERE creationDate >= '2012-04-01' + INTERVAL 1 DAY
-- After April
SELECT *
FROM mytable
WHERE creationDate >= '2012-04-01' + INTERVAL 1 MONTH
答案 1 :(得分:1)
WHERE DATE_FORMAT(creationDate, '%d/%m/%Y') >= STR_TO_DATE('01/05/2012', '%d/%m/%Y')
(你问的是2012年4月之后,可能是这样)
答案 2 :(得分:1)
SELECT * FROM mytable WHERE CreationDate > '2012-04-00'
答案 3 :(得分:1)