I have formatted date that looks like this;

date('l, F jS, Y', $data['expiry']))

$date['expiry'] displays something like this;

Tuesday, December 4th, 2007

However, instead i would like to show something like this;

Remaining Duration: 311 days 22 hours 51 minutes 48 seconds or along these lines.

$data['expiry'] is in format 1196787507 before it formatted.

I know i have to take todays date and subtract it from 1196787507 but im not sure how i should work with this for the conversion.

Thank you.

    The difference between expiry and [man]time[/man] will give you a number of seconds between now and then. The next thing would be to use division by number of seconds in a day ([man]floor[/man] for getting integer and remainder using % operator - modulus). Then the remainder should be treated similarly with the number of seconds in an hour.

    $difference = $data['expiry'] - time();
    //check here if it's positive or negative
    
    $days = $difference / (24*60*60);
    $remainder = $difference % (24*60*60);
    $hours = $remainder/(60*60);
    $seconds = $remainder % (60*60);
    
      wilku wrote:

      The difference between expiry and [man]time[/man] will give you a number of seconds between now and then. The next thing would be to use division by number of seconds in a day ([man]floor[/man] for getting integer and remainder using % operator - modulus). Then the remainder should be treated similarly with the number of seconds in an hour.

      $difference = $data['expiry'] - time();
      //check here if it's positive or negative
      
      $days = $difference / (24*60*60);
      $remainder = $difference % (24*60*60);
      $hours = $remainder/(60*60);
      $seconds = $remainder % (60*60);
      

      Thank you, i get the following on the output

      20.437638888889 days 10.503333333333 hours 37812 minutes 1812 seconds 🙂

        So is that what you were after? If so, don't forget to mark this thread resolved.

          Almost, i supposed i would need to do some kind of rouding?

            As wilku suggested, [man]floor/man will round down to the nearest integer, else you could do a normal [man]round/man operation.

              Write a Reply...