What are some potential pitfalls to avoid when working with timestamps in PHP and MySQL?

One potential pitfall when working with timestamps in PHP and MySQL is not handling timezones correctly, which can lead to discrepancies in the displayed timestamps. To avoid this issue, it is important to always set the timezone for both PHP and MySQL to ensure consistency in the timestamps.

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

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