-1

I am trying to display the number in hours since a date like this...

$timestamp1 = '1517158402';
$timestamp2 = '1530204802';
$timestamp3 = '1548694384';

if ($timestamp1 && $timestamp2 && $timestamp3 ) {

    /* Calculate time */
    $timestamp1_obj = new DateTime($timestamp1);
    $timestamp2_obj = new DateTime($timestamp2);
    $timestamp3_obj = new DateTime($timestamp3);

    $since_start = $timestamp2_obj->diff($timestamp3_obj);
    echo $since_start->h.' hours';

}

This is giving me the error message...

Uncaught Exception: DateTime::__construct(): Failed to parse time string

Anyone any ideas where I am going wrong?

4

1 Answer 1

4

You need to use setTimestamp.

$date = new DateTime();
$date->setTimestamp(1171502725);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, setTimestamp was exactly what was missing!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.