I want to insert two datetime's into mysql.
$taskcompdate is a user written string that needs to be converted into a datetime object and formatted with a "d/m/y" format.
The second, $datenow is simply the now time.
The insert query works, but all dates in all records are displayed as 0000-00-00 00:00:00
I tried every possible way I found, but none works. What am I doing wrong?
<?php
$conn = mysqli_connect("127.0.0.1", "root", "", "todo_list");
$taskname = $_POST["taskname"];
$taskcompdate = $_POST["taskcompdate"];
$datenow = date("H:i:s d/m/y");
$insert_date1 = date('d/m/y', strtotime($taskcompdate));
$insert_date2 = date('H:i:s d/m/y', strtotime($datenow));
$sql_main = "INSERT INTO task_main (task, complete_date, added_date) VALUES ('$taskname', '$insert_date1', '$insert_date2')";
$result = mysqli_query($conn, $sql_main);
if ($result) {
echo 'success';
} else {
echo 'failure' . mysqli_error($conn);
}
?>
$insert_date1and$insert_date2.