如何将数字数据类型的20220401的列值转换为雪花中的2022-04-01
我有一个数字数据类型的雪花列列存储像20220401这样的值,现在我需要将其转换为日期格式。有人可以帮忙吗
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有一个数字数据类型的雪花列列存储像20220401这样的值,现在我需要将其转换为日期格式。有人可以帮忙吗
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您可以使用to_date,但可以在char Datatype上使用,因此首先需要将列转换为char/string。
You can use to_date, but it works on char datatype, so first need to convert your column to char/string.
看到/说同样的话还有更多的方法:
to_date 允许您定义
给出:
如果您有有时不遵循格式模式的字符串,则您可能想使用
但鉴于您说的“数字输入”
现在我们有数字,但是to_date想要文本,因此我们将其施放给文本,因此可以使用解析器。
给予:
,如果您使用的是使用to_timestamp,它接受相同格式的字符串,裸体数字本身,它将认为您的意思是seconds,并给您带来的secoch,并给您带来的小小的微型数字,例如:类似:
这都是可以说,通过
指定您的格式,以便您可以处理yyyymmdd或yyyyddmm或每个数据的方式。
Yet more way's of seeing/saying the same thing:
to_date allows you to define format string
gives:
if you have string that sometimes are not following the format pattern you might want to use try_to_date as this will not generate an error:
But given you said "number input"
now we have numbers, but to_date wants text, so we cast it to text, so the parser can be used.
giving:
Now if you use TO_TIMESTAMP which accepts the same format string, the naked number by itself it will think you mean epoch seconds, and give you wacky tiny number, like:
which is all to say, cast it to string via
::text
or the likes, and specify your format, so that you can handle yyyymmdd or yyyyddmm or how every your data is.更多详细信息:
More details: https://docs.snowflake.com/en/sql-reference/functions/to_date.html#examples