user3123716
user3123716

Reputation: 11

Netezza: How to convert varchar to date

I have a VARCHAR column named FECHAATENDIDO with data in different formats, for example:

2013-07-04
14/08/2012
20080522

I need a query to obtain the year and month. This is how it was done in SQL Server:

SELECT product, year(fechaatendido) as year, month(fechaatendido) as month
FROM consulta where YEAR(fechaatendido)=2013;

How can I do the same with Netezza?

Upvotes: 1

Views: 3978

Answers (1)

Niederee
Niederee

Reputation: 4295

select consulta.FECHAATENDIDO
,date(consulta.FECHAATENDIDO) as date_FECHAATENDIDO
from (select cast('2013-07-04' as varchar(20)) as FECHAATENDIDO
union all
select cast('14/08/2012' as varchar(20))
union all
select cast('20080521' as varchar(20))
) consulta
where date_part('year',date(consulta.FECHAATENDIDO))=2013

Upvotes: 1

Related Questions