简体   繁体   English

如何在bigquery中更改字符串格式

[英]how to change string format in bigquery

I have a date column in string format stored in the big query.我有一个字符串格式的日期列存储在大查询中。 It is showing as dd-mm-yyyy.它显示为 dd-mm-yyyy。

I want to change it to yyyy-mm-dd but keep it in string format.我想将其更改为 yyyy-mm-dd 但保持字符串格式。

Such as 10-01-2023 to 2023-01-10.例如 10-01-2023 到 2023-01-10。

I am not sure how to do it, any help would be appreciated.我不确定该怎么做,我们将不胜感激。

Thanks谢谢

Keeping date as date data type makes more sense for any further calculations.将日期保留为日期数据类型对于任何进一步的计算都更有意义。

But if you really need it all in strings, here is how you can do it.但是如果你真的需要所有的字符串,这里是你如何做到的。 You can all do it in one go, but I've split into separate subqueries for your understanding.你们都可以在一个 go 中完成,但为了您的理解,我已经分成了单独的子查询。

select cast(actual_date as string) as reformatted_string_date from (
select parse_date('%m-%d-%Y', string_date) as actual_date 
from (select '10-01-2023' as string_date )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM