phpduration

How to convert duration from ISO format PT1h30M to int duration basing on number of minutes in php?


I want to convert a duration from ISO 8601 format to an integer by computing the number of minute in this duration. For exemple if I have PT1h30M, I want to convert it to 90, because I need to store this information in my data base as integer (the number of minute). Is there any function in PHP to do this?


Solution

  • There are a few answers out there relating to conversion of ISO 8601 format.

    Check out PHP 5.3+ DateInterval

    Also, Parse and create ISO 8601 Date and time intervals, like PT15M in PHP