简体   繁体   中英

Inserting '2011-12-20, 3:18PM EST' into MySQL Timestamp Column

I am trying to insert timestamps in the form of 2011-12-20, 3:18PM EST into a TIMESTAMP column in a MySQL table.

Problem: Inserting the string 2011-12-20, 3:18PM EST directly into the table gets me 2011-12-20 03:18:00 which is in AM! (Took me very long to discover this!!)

Now when I tried the following, I get a PHP error...

$time = '2011-12-20,  3:18PM EST';

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

I also tried inserting the output of strtotime('2011-12-20, 3:18PM EST') into the MySQL table, which just gets me 000-00-00 00:00:00 .

Question: Which is the correct way to insert the string like 2011-12-20, 3:18PM EST into the TIMESTAMP column of the table? I want 2011-12-20 15:18:00 to end up in that column.

Strip the 'EST' part:

echo date("Y-m-d H:i:s", strtotime('2011-12-20, 3:18PM'));

You could do that with substr () or str_replace ()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM