Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save PHP date string into MySQL database as timestamp

I am trying to save a datestring in PHP into a MySQL database as timestamp datatype. I found a lot of posts about this, but none of them worked for me. This is what I've tried:

$date =  $_POST['date'];
$timestamp = date("m/d/Y", strtotime($date));
$sql = "insert into sale(service, amount, date, customerid_fk) values('$service', '$amount', '$timestamp', '$id');";

But in the database, I only get:

0000-00-00 00:00:00

The input string from the POST object is 05/30/2013. Thanks a lot for your support!

like image 998
nimrod Avatar asked May 09 '13 08:05

nimrod


1 Answers

This might work for you:

$date =  $_POST['date'];
$timestamp = date('Y-m-d H:i:s', strtotime($date));  

 $sql = "insert into sale(service, amount, date, customerid_fk) values('$service', '$amount', '$timestamp', '$id');";
like image 191
Vijaya Pandey Avatar answered Sep 28 '22 09:09

Vijaya Pandey