Format of timesince filter

Viewed 10380

Is there a way to use the {{date|timesince}} filter, but instead of having two adjacent units, only display one?

For example, my template is currently displaying "18 hours, 16 minutes". How would I get it to display "18 hours"? (Rounding is not a concern here.) Thank you.

4 Answers

Well, you can make use of JS here. You need to add a script that splits the first and second units and then displays only the first one.

Say the part of your template looks like this:

<your_tag id="your_tag_id">{{date|timesince}}</your_tag>

Now, add the below script to your template.

<script>
        let timesince = document.getElementById("your_tag_id").innerHTML.split(",");
        document.getElementById("your_tag_id").innerHTML = timesince[0];
</script>
Related