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

<p>To do that, you could write a Craft <a href="http://buildwithcraft.com/docs/plugins/introduction" rel="nofollow">plugin</a> that adds a custom Twig extension that has a ScormIt filter that uses PHP's <a href="http://php.net/manual/en/dateinterval.construct.php" rel="nofollow">DateInterval</a> class to output it in the format that you're looking for.</p>

<p>That way, you could do something like:</p>

<pre><code>{{ videoObject.duration|ScormIt }}
</code></pre>

CC BY-SA 3.0
2014-10-03T18:19:07.113Z
Thanks Brad. Might be a good reason to get into writing a plugin. Seems feasible, even for me. :)
Marcus Scheller
CC BY-SA 3.0
2014-10-03T18:23:58.517Z
If @low can do it, anyone can. You can use his RegEx twig filter as a starting point: https://github.com/low/low_regex
Brad Bell
CC BY-SA 3.0
2014-10-03T17:41:10.917Z
2014-10-03T18:08:23.067Z
2014-10-03T18:08:23.067Z
Brad Bell
<p>I have a video Object with a duration property formatted in <a href="http://www.ostyn.com/standards/scorm/samples/ISOTimeForSCORM.htm" rel="nofollow">SCORM 2004 time format</a>. Like so: <strong>PT51M55S</strong>. How do i convert this into a human readable time format like: <strong>51:55</strong>? <code>date()</code> does not seem to work obviously.</p>

<templating><datetime><format><conversion>
Twig: Convert time format
# Twig: Convert time format

(Asked by: username_0 on 2014-10-03)

I have a video Object with a duration property formatted in [SCORM 2004 time format](http://www.ostyn.com/standards/scorm/samples/ISOTimeForSCORM.htm). Like so: **PT51M55S**. How do i convert this into a human readable time format like: **51:55**? `date()` does not seem to work obviously.

**Tags:** templating, datetime, format, conversion


---

## 1 answers

### Answer by username_1 on 2014-10-03. Score: 2

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 }}

> **Comments:**
> **username_0**: Thanks Brad. Might be a good reason to get into writing a plugin. Seems feasible, even for me. :)  
> **username_1**: If @low can do it, anyone can. You can use his RegEx twig filter as a starting point: https://github.com/low/low_regex  

---

