Convert char to valid mysql date

oracle

New Member
Messages
430
Reaction score
0
Points
0
Hello All,

I have date stored in the following format with varchar dataset:

March 31, 2008, 9:52 pm

I want to convert this to valid mysql date ?

Any suggestions ??
 

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
If that is a varchar type, it is still valid provided that it follows this kind of format : YYYYMMDDHHmmSS where Y is year, M is month, D is day, H for hour, m for minute and S for second. For more info check here

With that format you have, I suggest that you use substring function to get the info, or split that and give them an equivalent valid numeric date say March => 03 and PM.. to a valid 24 hour format.

HTH
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Try:

date('Y-m-d H:i:s', strtotime($date));

where $date is the varchar string from the db. That should be able to convert them to valid mysql datetime values provided that the format you gave is used for all of them.
 
Top