Home > OS >  How can i change date format via sql
How can i change date format via sql

Time:12-12

I have saved date in my database in 12-Oct-2021 12:27:53 pm this format. But I need to change it to 2021-10-12. How can i do it via SQL.

CodePudding user response:

You can try:

SELECT DATE(STR_TO_DATE('12-Oct-2021 12:27:53 pm', '%d-%b-%Y %r'))

More about STR_TO_DATE here.

CodePudding user response:

You can try:

SELECT CONVERT(DATE, '12-Oct-2021 12:27:53 pm', 106) 

Should give you:

2021-10-12

See if that works for you.

CodePudding user response:

You can try this,

select convert(varchar, getdate(), 23);

This will convert the date into yyyy-mm-dd format

  • Related