Search code examples
phptimestampunix-timestampdatediff

Difference in days between today and unix timestamp..


So first things first is DateDiff() the way to go?

<?php

$date1 = strtotime(1766253900); // expiry date
$date2 = strtotime(1539652560); // todays date
$dtDiff = $date1 - $date2;
$totalDays = intval($dtDiff/(24*60*60));
echo $totalDays
?>

I tried it this way but it is outputting 0 ZERO


Solution

  • Just remove strtotime as both dates are already UNIX timestamps i.e. number of seconds since 1970

    <?php
    
    $date1 = 1766253900; // expiry date
    $date2 = 1539652560; // todays date
    $dtDiff = $date1 - $date2;
    $totalDays = intval($dtDiff/(24*60*60));
    echo $totalDays
    ?>