substring from date

Database
Highlighted
Enthusiast

substring from date



Hello friends,


Can u help me how can i get the year part from date_1 using substring or any other way?
date_1 has datatype of varchar(10), so when i tried using Extract it didn't work.


date_1
9/21/2005
7/13/2001
1/11/2001
5/23/2005
10/15/2004
4/24/2006
3/24/2005
7/15/2003
2/25/2002
1/8/2003
11/25/2005
1/29/2001
5/19/1999
5/9/2002



Thanks



3 REPLIES
Enthusiast

Re: substring from date

This should work...

CAST(DATE_1 AS DATE) AS DATE_1_DT,
EXTRACT(YEAR FROM DATE_1_DT)

I put it in two steps to make it easier to read. You should also be able to do EXTRACT(YEAR FROM (CAST(DATE_1 AS DATE))).

Supporter

Re: substring from date

Hi Kavya,

select substring(date_1 FROM CHAR_LENGTH(date_1) - 3)

Dieter
Enthusiast

Re: substring from date



Hey


Thanks a lot.

Its working great.