skip to Main Content

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

2

Answers


  1. select convert(varchar, getdate(), 103) 
    

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

    Login or Signup to reply.
  2. 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');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search