I have a date variable as 24-dec-08
.
I want only the 08
component from it.
How do I do it in a select statement?
e.g.:
select db||sysdate
--(this is the component where I want only 08 from the date)
from gct;
I have a date variable as 24-dec-08
.
I want only the 08
component from it.
How do I do it in a select statement?
e.g.:
select db||sysdate
--(this is the component where I want only 08 from the date)
from gct;
The easiest way is to use the to_char
function this way:
to_char(sysdate, 'YY')
as documented here.
If you need the integer value, you could use the extract
function for dates too. Take a look here for a detailed description of the extract
syntax.
For example:
extract(YEAR FROM DATE '2008-12-24')
would return 2008.
If you just need the value of the last two digits, you could apply the modulo function MOD
:
mod(extract(YEAR FROM DATE '2008-12-24'), 100)
would return 8.
The normal way to do this in Oracle is:
select db||to_char(sysdate,'YY')
from gct;