简体   繁体   中英

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.

I want to change it to yyyy-mm-dd but keep it in string format.

Such as 10-01-2023 to 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.

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 )
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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