What are the best practices for storing timestamps in databases to avoid timezone discrepancies?

Storing timestamps in databases using UTC timezone is a common best practice to avoid timezone discrepancies. This ensures that timestamps are consistent across different timezones and can be easily converted to the local timezone when needed.

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

// Get the current timestamp in UTC
$timestamp = time();

// Store the timestamp in the database
$query = "INSERT INTO table_name (timestamp_column) VALUES ($timestamp)";
// Execute the query