What is the best way to store the end time of an advertisement in a MySQL database using PHP?

When storing the end time of an advertisement in a MySQL database using PHP, it is best to use the DATETIME data type to ensure accurate storage and retrieval of the timestamp. This allows for easy comparison and manipulation of the end time in your database queries.

// Assuming $endTime is the variable containing the end time of the advertisement
$endTime = date('Y-m-d H:i:s', strtotime('2022-12-31 23:59:59'));

// Establish a connection to the MySQL database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$conn = new mysqli($servername, $username, $password, $dbname);

// Insert the end time into the database
$sql = "INSERT INTO advertisements (end_time) VALUES ('$endTime')";
$conn->query($sql);

// Close the database connection
$conn->close();