Search This Blog

Thursday, September 9, 2010

Date between DATE_1 and DATE_2

When ever we try to implement

select ..................
from ..................
where DATA_PARAMETER_FROM_OUT_SIDE
between
DATE_1(from database)
and
DATE_2(from database);


consider that the date from database will have the time portion, So the above statement will consider date range between Mid night (12 AM) of DATE_1 to Mid night (12 AM) of DATE_2.

DATE_1 is good but DATE_2 is the issue.

Records with DATA_2 time portion 12 AM will be pulled and not complete DATE_2.


Solution :

Truncate the time portion.


select ..................
from ..................
where DATA_PARAMETER_FROM_OUT_SIDE 
between
Trunc(DATE_1(from database))
and 
Trunc(DATE_2(from database));

No comments:

Post a Comment