Question

We have a Netezza table that contains dates stored in a numeric YYYYMMDD format (eg 20090731).

What is the best Netezza syntax to use to convert this into date format?

eg

SELECT somefunction(20090731) as NZDATE

?

Was it helpful?

Solution

Easiest way to convert number to date would be

select  date(to_char(20090731,'99999999')) as Number_As_DATE;

OTHER TIPS

You can use this one as it's the best one.

SELECT TO_DATE('20090731','YYYYMMDD') as NZDATE
to_date (sk_dim_time ,'YYYYMMDD')

My efforts were thwarted originally due to invalid dates. The code bellow does work as long as you wrap it in a statement to catch bad dates.

select  to_date(substring(20090731 from 1 for 8),'YYYYMMDD') as NZDATE

Obviously 20090731 should be replaced with the name of the numeric variable.

select to_date(20090731,'YYYYMMDD') as Number_As_DATE

This will work without converting to char.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top