Netezza SQL 语法将数字 YYYYMMDD 格式转换为日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1211412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:02:08  来源:igfitidea点击:

Netezza SQL syntax to convert numeric YYYYMMDD format into date

sqlnetezza

提问by Allan Bowe

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

我们有一个 Netezza 表,其中包含以数字 YYYYMMDD 格式(例如 20090731)存储的日期。

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

用于将其转换为日期格式的最佳 Netezza 语法是什么?

eg

例如

SELECT somefunction(20090731) as NZDATE

?

?

回答by user447151

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

你可以使用这个,因为它是最好的。

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

回答by Ian

Easiest way to convert number to date would be

将数字转换为日期的最简单方法是

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

回答by Dania

to_date (sk_dim_time ,'YYYYMMDD')

回答by Allan Bowe

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 20090731should be replaced with the name of the numeric variable.

显然20090731应该替换为数值变量的名称。

回答by bithom

select to_date(20090731,'YYYYMMDD') as Number_As_DATE

This will work without converting to char.

这将在不转换为字符的情况下工作。