What are some common pitfalls when working with dates in PHP and MySQL?

One common pitfall when working with dates in PHP and MySQL is not properly handling time zones. To ensure consistency, it's important to set the time zone for both PHP and MySQL to the same value. This can be done by using functions like date_default_timezone_set() in PHP and setting the time zone in MySQL configuration.

// Set the time zone for PHP
date_default_timezone_set('America/New_York');

// Set the time zone for MySQL
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
$mysqli->query("SET time_zone = 'America/New_York'");