What are the advantages of using a proper date format like DATETIME for date storage in MySQL when working with PHP?

When working with dates in MySQL and PHP, it is important to use a proper date format like DATETIME for date storage. This ensures that dates are stored accurately and can be easily manipulated and queried within the database. Using DATETIME also allows for proper sorting and comparison of dates, making it easier to work with date-related data in your PHP application.

// Example of storing a date in MySQL using DATETIME format
$date = date("Y-m-d H:i:s"); // Get current date and time in proper format
$query = "INSERT INTO table_name (date_column) VALUES ('$date')";
$result = mysqli_query($connection, $query);
if($result) {
    echo "Date stored successfully!";
} else {
    echo "Error storing date: " . mysqli_error($connection);
}