What are the common pitfalls when handling timestamps in PHP, especially with MySQL databases?

Common pitfalls when handling timestamps in PHP, especially with MySQL databases, include not setting the correct timezone, using the wrong format for timestamps, and not properly converting between PHP timestamps and MySQL datetime format. To avoid these issues, always set the timezone explicitly, use the correct format for timestamps, and convert timestamps appropriately when interacting with MySQL.

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

// Get current timestamp in PHP
$timestamp = time();

// Convert PHP timestamp to MySQL datetime format
$mysql_datetime = date('Y-m-d H:i:s', $timestamp);

// Convert MySQL datetime to PHP timestamp
$php_timestamp = strtotime($mysql_datetime);