How to find out tomorrow's or yesterday's date in timestamp format in PHP?

How to find out tomorrow's or yesterday's date in timestamp format in PHP?

To get yesterday’s or tomorrow’s date in timestamp format (PHP), you need to use the standard PHP function "strtotime".

For example, let’s display the time of the current date at 00:00:00 (zero hours, zero minutes, zero seconds):

$t = strtotime('00:00:00');
echo 'Timestamp: '.$t;
echo 'Datetime: '.date('Y-m-d H:i:s',$t);

Now the same, but for yesterday:

$t = strtotime('-1 day 00:00:00');
echo 'Timestamp: '.$t;
echo 'Datetime: '.date('Y-m-d H:i:s',$t);

And the same for tomorrow:

$t = strtotime('+1 day 00:00:00');
echo 'Timestamp: '.$t;
echo 'Datetime: '.date('Y-m-d H:i:s',$t);

Similarly, you can add weeks and other time periods as needed.

Posts on similar topics

Are you having problems with your WordPress site? Do you need additional functionality? A custom plugin or a new page?
Then write to me via the feedback form, and I will try to help you.

Write a comment

Your email address will not be published. Required fields are marked *