Reputation: 223
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);
Upvotes: 3
Views: 16860
Reputation: 7882
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/
Upvotes: 3