Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
...WHERE TRUNC(<some date>) = TRUNC(SYSDATE)...
Don't do that.How about using to_date on a date field?
That is its purpose.Or to_date can only be used on a string
All DATE expressions in Oracle always contain a TIME component, even after a TRUNC has done its work. In the case of a TRUNC(<date>), the TIME component becomes "00:00:00" (i.e., midnight at the beginning of a particular DATE).Ekta said:so TRUNC gets rid of the time portion for the date time field?
SQL> col a format a24 heading "Current Date/Time"
SQL> col b format a24 heading "TRUNC'd Date/Time"
SQL> REM Mask: 'mi' = Snap down to 'Minute' boundary
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'mi'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:23 Tue, 2007-12-04 13:13:00
SQL> prompt
SQL> REM Mask: 'hh' = Snap down to 'Hour' boundary
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'hh'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:23 Tue, 2007-12-04 13:00:00
SQL> prompt
SQL> REM Mask: none = Snap down to 'Current Day' boundary (same as using 'DD')
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:23 Tue, 2007-12-04 00:00:00
SQL> prompt
SQL> REM Mask: 'd' = Snap down to 'Beginning of the Calendar Week' boundary
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'D'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:24 Sun, 2007-12-02 00:00:00
SQL> prompt
SQL> REM Mask: 'W' = Snap down to 'Beginning of the Week From 1st Day of Month'
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'w'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:24 Sat, 2007-12-01 00:00:00
SQL> prompt
SQL> REM Mask: 'WW' = Snap down to 'Beginning of the Week From 1st Day of Year'
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'wW'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:24 Mon, 2007-12-03 00:00:00
SQL> prompt
SQL> REM Mask: 'MM' = Snap down to '1st of the Month'
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'MM'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:25 Sat, 2007-12-01 00:00:00
SQL> prompt
SQL> REM Mask: 'Q' = Snap down to '1st Day of the Calendar Quarter'
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'Q'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:25 Mon, 2007-10-01 00:00:00
SQL> prompt
SQL> REM Mask: 'Y' or 'YY' or 'YYY' or 'YYYY'= Snap down to '1st Day of the Year'
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'Y'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:25 Mon, 2007-01-01 00:00:00
SQL> prompt
SQL> REM Mask: 'CC' = Snap down to '1st Day of the Century'
SQL> select to_char(sysdate,'Dy, YYYY-mm-dd hh24:mi:ss') a
2 ,to_char(trunc(sysdate,'CC'),'Dy, YYYY-mm-dd hh24:mi:ss') b
3 from dual
4 /
Current Date/Time TRUNC'd Date/Time
------------------------ ------------------------
Tue, 2007-12-04 13:13:26 Mon, 2001-01-01 00:00:00
SQL>
Oracle allows the TO_DATE function on character strings only, not on DATE expressions (since DATEs are already DATEs <grin>).Ekta said:How about using to_date on a date field? Or to_date can only be used on a string?