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
CodePudding user response:
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 )
)