Hello everyone, I have a problem: there is a final date in Unix - 1353096809 and there is a current time caused by the time () function, let's say it is 1353011685, so I have to calculate how much time is left before 1353096809 (this date). When I just take away:

<?=$date_end - time()?> 

Everything is fine, but when I try to convert it to a date with:

 <?=date("g:i:s", $date_end - time());?> 

I’m getting a little less than 2 hours, although I’m supposed to be a little less than 23 hours, why is the date incorrectly displayed?



    3 answers 3

    Wrong formatting option set:

    g - clock, 12-hour format, without first zero.

    You need a G - clock, 24-hour format, without the first zero.

    Those. :

     $date_end = 1353096809; $time = time(); echo date("dmY G:i:s", $date_end); echo date("dmY G:i:s", $time); echo date("G:i:s", $date_end - $time); /* Результат 16-11-2012 23:13:29 16-11-2012 17:20:15 8:53:14 */ 
    • Here! Thank you, this is what was needed !! Thanks again :) - Csharp

    The date function with the second parameter takes a timestamp . In your case, you just need to divide by 60 to find out how many minutes and again 60, how many hours

    • Yes, but I need to get in the end something like this: 12:06:14 hours / minutes / seconds And I did as you said: I did it: 375869.478056 - minutes ... - Csharp

    date_diff to help you

    DateTime::diff -- date_diff - Returns the difference between two DateTime objects.