How do I truncate a date in PLSQL?

I have a date variable like 24-dec-08. I only need a component 08.

How to do this in a select statement?

eg:.

select db||sysdate 
--(this is the component where I want only 08 from the date) 
from gct;
+3
source share
2 answers

The easiest way is to use the function to_charas follows:

to_char(sysdate, 'YY')

as described here .

If you need an integer value, you can also use a function extractfor dates. See here for a detailed description of the syntax extract.

For example:

extract(YEAR FROM DATE '2008-12-24')    

2008 will return.

, modulo MOD:

mod(extract(YEAR FROM DATE '2008-12-24'), 100) 

8.

+8

Oracle:

select db||to_char(sysdate,'YY')
from gct;
+1

All Articles