Skip to content
Advertisement

How to convert a Datetime string to standard mysql

I made a function in php to convert date and time coming from a txt to the mysql standard. But she is turning the month wrong. I have tried all these conversions but to no avail. I would like your help because I don’t know what else to do.

JavaScript

Advertisement

Answer

Since you know the format of your datetime-string I suggest you use createFromFormat() like so:

JavaScript

Note that I am not sure if 05 or 02 is supposed to be the month in your example, so if this seems wrong to you you might just have to switch around d/m in the format string and make it m/d.

For explanation what character means what poriton of the datetime, see the linked above documentation reference.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement