In mysql , the data type is integer... And I want to save date as 1422104820 format (timestamp).
$Date = $_POST['Date'];
$Time = $_POST['myTime'];
$Date1 = $Date.$myTime;
insert into table ('date') values ($Date1);
You can use one of this two ways to get the timestamp:
// Use the strtotime() function
$timestamp = strtotime($Date1);
// DateTime class.
$date = new DateTime($Date1);
$timestamp = $date->getTimestamp();
NOTE ABOUT PERFORMANCE:
The structured style (
strtotime()) is faster than the Object-oriented style (DateTime).
You can see an interesting benchmark of this two ways to get the timestamp here:
http://en.code-bude.net/2013/12/19/benchmark-strtotime-vs-datetime-vs-gettimestamp-in-php/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With