The simplest way is to use the trunc()
function, which by default sets the time portion of the date value to midnight:
SELECT trunc(close_date), close_UIN, ...
...
group by trunc(close_date), close_UIN
order by close_UIN
Note that you need to truncate the value in the select list and the group-by clause. The function can optionally truncate to a different precision too, like removing seconds, or going to the first day of the month, etc.:
select sysdate, trunc(sysdate), trunc(sysdate, 'SS') from dual;
SYSDATE TRUNC(SYSDATE) TRUNC(SYSDATE,'MI')
------------------- ------------------- -------------------
2015-05-01 09:37:48 2015-05-01 00:00:00 2015-05-01 09:37:00
See the docs for more info.
This is not correct:
AND TO_DATE (close_date ,'DD-MON-YY') BETWEEN TO_DATE
('~Date From~', 'DD/MM/YYYY') AND TO_DATE('~Date To~','DD/MM/YYYY')
Since close_date
is already a date column you're doing an implicit conversion to a string using your NLS_DATE_FORMAT, and then an explicit conversion back to a date using 'DD-MON-YY' - which is using a two-digit year and will cause its own problems. The behaviour may vary for other users with different settings.
It looks like you're trying to do the equivalent of a trunc()
to make the between
cover the whole of the final day, but you won't get the year (century) you expect. And calling any function on the column will prevent any index on it being used, unless you have a matching function-based index (but using trunc()
only in the select list and group by is OK).
If you want all records from the start of 'date from' to the end of 'date to' you can specify that with a range instead of 'between' - which is inclusive but might not get the result you expect depending on your NLS settings, again. Something like:
AND close_date >= TO_DATE('~Date From~', 'DD/MM/YYYY')
AND close_date < TO_DATE('~Date To~','DD/MM/YYYY') + 1
Less than midnight on the day after 'date to' is equivalent to saying up to 23:59:59 on 'date to', i.e. covering that entire day.