I have a video Object with a duration property formatted in SCORM 2004 time format. Like so: PT51M55S. How do i convert this into a human readable time format like: 51:55? date() does not seem to work obviously.


I'm not sure this is possible in Twig alone, but it should be easy enough in PHP.

To do that, you could write a Craft plugin that adds a custom Twig extension that has a ScormIt filter that uses PHP's DateInterval class to output it in the format that you're looking for.

That way, you could do something like:

{{ videoObject.duration|ScormIt }}
  • Thanks Brad. Might be a good reason to get into writing a plugin. Seems feasible, even for me. :) Oct 3 '14 at 18:19
  • 1
    If @low can do it, anyone can. You can use his RegEx twig filter as a starting point: github.com/low/low_regex
    – Brad Bell
    Oct 3 '14 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.