today i ran in to a problem,
i want to make a input field where people can select a date and put that date into my mysql database with the timestamp type. How can i do something like that
My database looks like this
The timestamp is inserted automatically as your date column in the database is flagged with
CURRENT_TIMESTAMP
Just pass an empty value.
You need to store it in this format "Y-m-d H:i:s".
If it's not already in the above format use the DateTime class.
$userInput = "20/12/2016";
$date = DateTime::CreateFromFormat("d/m/Y", $userInput);
You'll now have a datetime object. With that you can format it using
$date->format('Y-m-d H:i:s);
Note: I'd personally use a DateTime field rather than a timestamp field.
I don't know what exactly you want.
$date = $_POST['date'];
$timestamp = date('Y-m-d H:i:s', strtotime($date));
then insert $timestamp
into your database.