0

I got error when i try to change string to date.

mysql> select STR_TO_DATE('03.05.2010 00:00','%d.%m.%Y %h:%i');
+--------------------------------------------------+
| STR_TO_DATE('03.05.2010 00:00','%d.%m.%Y %h:%i') |
+--------------------------------------------------+
| NULL                                             |
+--------------------------------------------------+
1 row in set, 2 warnings (0,00 sec)

how can i convert to date from '03.05.2010 00:00' ? Thanks

2
  • 1
    min and seconds are always 00:00?
    – McNets
    Commented Mar 10, 2017 at 11:32
  • 1
    just to add for answer - %h it from 01 to 12, %H - 00-23
    – a_vlad
    Commented Mar 10, 2017 at 11:40

1 Answer 1

2

Use %H instead of %h.

select STR_TO_DATE('03.05.2010 00:00','%d.%m.%Y %H:%i');

Or, if HH:MM are always 00:00 you can use date part only:

select STR_TO_DATE('03.05.2010 00:00','%d.%m.%Y');

Check it here: http://rextester.com/CCPKR29919

As @a_vlad has pointed out on his comments, %H is used to format hours as 00..23 and %h as 01..12.

Have a look at DATE_FORMAT() on MySql docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.