phpdatetimeminute

How to get time in seconds from d-m-y h:i:s?


I found this:

$minutes = (strtotime("2012-09-21 12:12:22") - time()) / 60;

In this question

But the string from the API that I took is like 06-09-19 | 16:23:17 and this code don't work at all.

How can I do?

Thanks.


Solution

  • You'll need to manually parse that date format as it is non-standard using DateTime::createFromFormat:

    $date = DateTime::createFromFormat('d-m-y \| H:i:s', '06-09-19 | 16:23:17');
    $minutes =  ( $date->format('U')-time() ) / 60;