1

I have this object created in my web page.

input type="datetime-local" name="datentime" size="15" style="height:30px; font-size:18px" placeholder="

Now I need to retrieve the value and put it into my mysql database. I tried a lot but couldn't insert value to database. my php code is given below.

$event_dnt = strtotime($_POST["datentime"]);

database store as YYYY-MM-DD HH:MM:SS

1
  • 3
    The code you show won't insert anything into a table. It's just assigning a value to a variable. Show your code, and show the table schema. Commented Jun 20, 2018 at 8:28

2 Answers 2

3

Convert date from dd/mm/yyyy h:i (Default for input type datetime-local format) to Y-m-d H:i:s (Mysql format) to save in database, use code following:

date("Y-m-d H:i:s", strtotime($_POST["datentime"]))
Sign up to request clarification or add additional context in comments.

Comments

0

You must convert timestamp time (which return strtotime function) to database format string.

For example,

$_POST["datentime"] = '20.06.2018 10:12:45'; # OR '2018-06-08 10:12:45' -- just input sumulation
$data = $_POST["datentime"];
$dbInsertDate = date('Y-m-d H:i:s', strtotime($data));

In addition, check $_POST["datentime"] for needed format by regexp.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.