Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: TIMESTAMP: TRUNC Jump to:  
Category: >> Oracle PL/SQL >> TIMESTAMP: TRUNC Bookmark and Share

<< lastnext >>

Snippet Name: TIMESTAMP: TRUNC

Description: The trunc function returns a date truncated to a specific unit of measure.

Also see:
» FUNCTIONS: date/time
» TIMESTAMP: TZ_OFFSET
» TIMESTAMP: SysTimeStamp
» TIMESTAMP: SYS_EXTRACT_UTC
» TIMESTAMP: SessionTimeZone
» TIMESTAMP: LocalTimestamp
» TIMESTAMP: FROM_TZ
» TIMESTAMP: EXTRACT
» TIMESTAMP: DUMP
» TIMESTAMP: DBTIMEZONE
» TIMESTAMP: Get current timestamp
» TIMESTAMP: List time zones

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 04th, 2009

TRUNC ( DATE, [ format ] )
 
-- date is the date to truncate.
-- format is the unit of measure to apply for truncating. 
 
-- If the format parameter is omitted, the trunc function 
-- will truncate the date to the day value, so that any hours, 
-- minutes, or seconds will be truncated off.
 
SELECT TO_CHAR(SYSTIMESTAMP) FROM dual;
 
SELECT TO_CHAR(TRUNC(SYSTIMESTAMP)) FROM dual;
 
TRUNC(TO_DATE('22-AUG-03'), 'YEAR') -- would return '01-JAN-03'
TRUNC(TO_DATE('22-AUG-03'), 'Q') -- would return '01-JUL-03'
TRUNC(TO_DATE('22-AUG-03'), 'MONTH') -- would return '01-AUG-03'
TRUNC(TO_DATE('22-AUG-03'), 'DDD') -- would return '22-AUG-03'
TRUNC(TO_DATE('22-AUG-03'), 'DAY') -- would return '17-AUG-03'
 
 
/*
Unit       Valid format parameters
Year       SYYYY, YYYY, YEAR, SYEAR, YYY, YY, Y
ISO Year   IYYY, IY, I
Quarter    Q
Month      MONTH, MON, MM, RM
Week       WW
IW         IW
W          W
Day         DDD, DD, J
Start day of the week    DAY, DY, D
Hour       HH, HH12, HH24
Minute     MI
*/


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 253 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?