Skip to content

All topics  /  PHP

Add 24 Hours To Unix Timestamp In PHP Example

PHP ·

Teams applying “Add 24 Hours To Unix Timestamp In PHP Example” in a production project can use Monitask to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.

Before copying the example into a live application, confirm version-specific behaviour with the PHP project and test it against the project’s actual database and runtime.

Add 24 Hours To Unix Timestamp In PHP Example

Hi friend,

This example is add 24 hours to unix timestamp in php example.

The Unix timestamp is designed to track time as a running total of seconds from the Unix Epoch on January 1st, 1970 at UTC. To add 24 hours to a Unix timestamp we can use any of these methods:

So let's start following example.

Example : 1


The Unix timestamp is designed to track time as a running total of seconds from the Unix Epoch on January 1st, 1970 at UTC. To add 24 hours to a Unix timestamp we can use any of these methods.

Convert 24 hours to seconds and add the result to current Unix time.

<?php
    $current_Unix_time = time() + (24*60*60);
    echo $current_Unix_time;
?>

Output:

1640061403

Example : 2

Since hours in a day vary in systems such as Daylight saving time (DST) from exactly 24 hours in a day. It’s better to use PHP strtotime() Function to properly account for these anomalies. Using strtotime to parse current DateTime and one day to timestamp.

<?php
    $today_time = strtotime("now");
    $plus_one_day = strtotime('+1 day');
    echo $today_time."<br>";
    echo $plus_one_day;
?>

Output:

1639975484
1640061884

Example : 3

Using DateTime class we can achieve same result. First create a DateTime object with current timestamp and add interval of one day. P1D represents a Period of 1 Day interval to be added.

<?php
    // Get current time stamp
    $now = new DateTime();
    $now->format('Y-m-d H:i:s');    
    echo $now->getTimestamp(), "<br>";   

  
    // Add interval of P1D or Period of 1 Day
    $now->add(new DateInterval('P1D'));
    echo $now->getTimestamp();
?>

Output:

1639975484
1640061884

I hope it can help you......