user1048676
user1048676

Reputation: 10066

Convert a Date to a useable format to insert into MySQL

All, I have the following date:

Wed Feb 01 2012 09:30:00 GMT-0600 (Central Standard Time)

I'm trying to insert this into my mySQL database. The field I want to insert this into has a structure of DATETIME. Is there a simple way to insert this or do I have to do something to insert in correctly into the DATETIME correctly?

I don't think my hosting company has the highest version of PHP to use DateTime as well.

Thanks!

Upvotes: 0

Views: 237

Answers (2)

Kiran
Kiran

Reputation: 921

$date='Wed Feb 01 2012 09:30:00 GMT-0600';
$targetDate = date('Y-m-d H:i:s',strtotime($date));

date() function is bundled with all versions of php . You can convert date from any format .

Upvotes: 0

xdazz
xdazz

Reputation: 160833

date('Y-m-d H:i:s', strtotime('Wed Feb 01 2012 09:30:00 GMT-0600'))

Upvotes: 2

Related Questions