Search code examples
mysqldatedate-formatstr-to-date

MySQL: STR_TO_DATE with YYWW


How do you use MySQL with YYWW instead of YYYYWW?

My field looks like this:

wYYWW, for example w1310, w1506 and so on.

%x and %X seems to need 4 digits, and therefor it doesn't work.

Is there anyway to solve this problem?


Solution

  • How about stuffing the characters you need into the string? Something like this:

    select str_to_date(insert(col, 1, 1, '20'), '%X%u')