In the context of PHP and MySQL, what are some best practices for handling date calculations and comparisons to ensure accurate results?

When working with dates in PHP and MySQL, it's important to ensure that both systems are using the same timezone to avoid discrepancies in calculations and comparisons. One way to achieve this is by setting the timezone in both PHP and MySQL to a consistent value, such as UTC. This can help prevent issues like incorrect date offsets or unexpected results when performing date-related operations.

// Set the timezone for PHP
date_default_timezone_set('UTC');

// Set the timezone for MySQL
$mysqli = new mysqli("localhost", "username", "password", "database");
$mysqli->query("SET time_zone = '+00:00'");