开发者

Oracle date comparisons

Say I have the following code

Some Sql query... is followed by this condition

AND EndDate < TO_DATE('02/14开发者_JAVA百科/2011','MM/DD/YY')+1

Is it that same as

AND EndDate <= TO_DATE('02/14/2011','MM/DD/YY')


Note: I am assuming based on your to_date formatting that the EndDate is a date field and not a date/time data type.

Both queries should return the same result set. Consider the following:

--Substitue "EndDate" for SYSDATE for this exercise

-- Does "EndDate" occur before June 01, 2011? (Yes)
SELECT 'TRUE'
FROM DUAL
WHERE  TRUNC(SYSDATE) < TO_DATE('05/31/2011','MM/DD/YY')+1

-- Does "EndDate" occur on or before May 31, 2011? (Yes)
SELECT 'TRUE'
FROM DUAL
WHERE  TRUNC(SYSDATE) <= TO_DATE('05/31/2011','MM/DD/YY')

Both results would yield "TRUE". What doubts are you having?


Depends if EndDate is a DateTime or just a Date. If EndDate = 2/14/2011 3:00:00, the second one would be false but the first true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜