Skip to content
PHP Logo

In PHP, what are the best practices for converting day, month, and year values to a UNIX timestamp for date comparison in a MySQL query?

When converting day, month, and year values to a UNIX timestamp for date comparison in a MySQL query, it's best to use the mktime() function in PHP to create a timestamp from the individual date components. This ensures that the timestamp is accurate and can be easily compared in MySQL queries.

php
// Example of converting day, month, and year values to a UNIX timestamp
$day = 15;
$month = 6;
$year = 2022;

$timestamp = mktime(0, 0, 0, $month, $day, $year);