Home > database >  is there any way to convert dates in the long-format 'September 21, 2022' to just standard
is there any way to convert dates in the long-format 'September 21, 2022' to just standard

Time:09-05

is there any way to convert dates in the long-format 'September 21, 2022' to just standard DD/MM/YYYY formats?

CodePudding user response:

You can use to_date() to convert the string to a date:

to_date('September 21, 2022', 'Month dd, yyyy')

This returns a proper date value - the formatting depends on the SQL client displaying that value. If you just want to use it in your code, then keep it as a date. If you really do need to format that date back into a string (because e.g. your SQL client uses a format you don't like and can't change), then you can use to_char() on that result:

to_char(to_date('September 21, 2022', 'Month dd, yyyy'), 'YYYY-MM-DD');

CodePudding user response:

select convert(varchar, getdate(), 103) 

You can change the format by changing the number of the format you need , 103 or else .

  • Related