How to convert a string year to a DATE



  • STR_TO_DATE doesn't work like I expect.

    STR_TO_DATE('2007', '%Y') STR_TO_DATE('2007', '%y')
    2006-11-30 2019-11-30

    10.6.7-MariaDB-1:10.6.7+maria~bullseye-log



  • Use string operations instead:

    mysql> SELECT CONCAT('2007', '-01-01') + INTERVAL 360 DAY;
    +---------------------------------------------+
    | CONCAT('2007', '-01-01') + INTERVAL 360 DAY |
    +---------------------------------------------+
    | 2007-12-27                                  |
    +---------------------------------------------+
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2