All Forums Database
Kavya2007 12 posts Joined 09/06
17 Oct 2006
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_19/21/20057/13/20011/11/20015/23/200510/15/20044/ 24/20063/24/20057/15/20032/25/20021/8/200311/25/20051/ 29/20015/19/19995/9/2002Thanks

ThisIsBob 6 posts Joined 09/06
17 Oct 2006

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))).

dnoeth 2966 posts Joined 11/04
18 Oct 2006

Hi Kavya,select substring(date_1 FROM CHAR_LENGTH(date_1) - 3)Dieter

Dieter

Kavya2007 12 posts Joined 09/06
18 Oct 2006

Hey Thanks a lot. Its working great.

You must sign in to leave a comment.