0

I am trying to use STR_TO_DATE in my MySQL code, but my string does not include a day.

SELECT STR_TO_DATE('August 2020', '%M %Y')

This code returns null. I can get this function to work if I have a day in my date like:

SELECT STR_TO_DATE('August 20, 2020', '%M %d, %Y')

Is it because I'm formatting it wrong? Or does MySQL not support this functionality? If it doesn't support it is there a way around it?

Image of it shown in DBeaver

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
lex449
  • 139
  • 1
  • 12
  • This is working fine : SELECT STR_TO_DATE('August 2020', '%M %Y') returning - 2020-08-00. – Gopi Feb 20 '19 at 20:03
  • I added an image above showing that I tried that same line and it still returned [NULL] – lex449 Feb 20 '19 at 20:09
  • It seems the format is working with version 5.6 but with latest version 8.0.13 it's not working. – Gopi Feb 20 '19 at 20:21

1 Answers1

0

The issue is related with MySql version. You can use

select STR_TO_DATE(CONCAt('1 ','August 2020'), '%d %M %Y')
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72