Display X minute / hours / days in entries I am trying to print if statement for x time or x day ago for each published entries. For example the entry is posted x minutes ago should display x minutes ago or x hours ago. Same for days and months.

Here is what I have used but not what I am after. 

{{ date(category.dateCreated|date('c')).diff(now).format('%a') }}


But the code I have written does not work.

{% for category in entries %}

{% for time in category %}
&lt;span&gt;{{ date(time.dateCreated|date('c')).diff(now).format('%i') }} minutes ago&lt;/span&gt;

{% else %}
&lt;span&gt;{{ date(time.dateCreated|date('c')).diff(now).format('%h') }} hours ago&lt;/span&gt;

{% else %}
&lt;span&gt;{{ date(time.dateCreated|date('c')).diff(now).format('%d') }} days  agos&lt;/span&gt;
{% endfor %}
{% endfor %}


The above code is too long or is there a better way to check whether the entry is posted min, hours, or days ago.
Check out the DateTimeHelper method timeAgoInWords. It will do what you are after.

https://craftcms.com/classreference/helpers/DateTimeHelper#timeAgoInWords-detail

There is even a handy twig filter available for use in your templates.

{{ entry.dateCreated|timeAgoInWords }}