1.6K
To insert datetime in MySQL datetime column using PHP you can use date() of PHP.
<?php $mysqltime = date ('Y-m-d H:i:s', $phptime); ?>
MySQL expects a numeric representation of the format YYYY-MM-DD H:i:s. For Example 2022-07-07 16:30:10.
Date function provides an output in the required format.
If you want to change a variable into the required format You can use the follow:
$yourdate = "2022-07-07 16:30:10";
$dateinMySQLFormat= date("d-m-Y", strtotime($yourdate));