Skip to content
PHP Logo

Is there a recommended method for resetting a timestamp to 0:00 hours in PHP?

When resetting a timestamp to 0:00 hours in PHP, you can achieve this by setting the hours, minutes, and seconds components of the timestamp to 0. This can be done using the date() and strtotime() functions in PHP to manipulate the timestamp accordingly.

php
// Example code to reset a timestamp to 0:00 hours
$timestamp = strtotime('2022-01-01 12:34:56');
$reset_timestamp = strtotime(date('Y-m-d', $timestamp));

echo date('Y-m-d H:i:s', $reset_timestamp); // Output: 2022-01-01 00:00:00