Can you provide examples or resources for properly using date and time functions in PHP and MySQL queries?

When working with date and time functions in PHP and MySQL queries, it's important to properly format the dates and times to ensure accurate results. One common issue is not using the correct date format when inserting or querying dates in MySQL. To solve this, make sure to use the proper date functions in PHP to format the dates before inserting them into the database or querying them.

// Example of inserting a formatted date into MySQL using PHP
$date = date('Y-m-d H:i:s'); // Format the current date and time
$query = "INSERT INTO table_name (date_column) VALUES ('$date')";
$result = mysqli_query($connection, $query);
if ($result) {
    echo "Date inserted successfully!";
} else {
    echo "Error inserting date: " . mysqli_error($connection);
}