Answers.Body: <p>Check out the <code>DateTimeHelper</code> method <code>timeAgoInWords</code>. It will do what you are after.</p>
  
  <p><a href="https://craftcms.com/classreference/helpers/DateTimeHelper#timeAgoInWords-detail" rel="nofollow noreferrer">https://craftcms.com/classreference/helpers/DateTimeHelper#timeAgoInWords-detail</a></p>
  
  <p>There is even a handy twig filter available for use in your templates.</p>
  
  <p><code>{{ entry.dateCreated|timeAgoInWords }}</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-20T23:34:04.583Z
Answers.LastActivityDate: 2017-03-20T23:34:04.583Z
Answers.UserDisplayName: Fyrebase
Body: <p>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.</p>
  
  <p>Here is what I have used but not what I am after. </p>
  
  <pre><code>{{ date(category.dateCreated|date('c')).diff(now).format('%a') }}
  </code></pre>
  
  <p>But the code I have written does not work.</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
  <p>The above code is too long or is there a better way to check whether the entry is posted min, hours, or days ago.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-20T03:25:09.857Z
Comments.Text: Check out the `DateTimeHelper` method `timeAgoInWords`. It will do what you are after.
  
  https://craftcms.com/classreference/helpers/DateTimeHelper#timeAgoInWords-detail
Comments.UserDisplayName: Fyrebase
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-20T08:27:44.037Z
Comments.Text: @Fyrebase Well I learned something today. You should post this as an answer.
Comments.UserDisplayName: Stephen Lewis
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-04T15:02:18.280Z
Comments.Text: Any idea what the Craft 3 version of `timeAgoInWords()` is?
Comments.UserDisplayName: Sandwich
Tags: <templating><datetime>
Title: Display X minute / hours / days in entries
ThreadText: # Display X minute / hours / days in entries
  
  (Asked by: username_0 on 2017-03-19)
  
  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 %}
  <span>{{ date(time.dateCreated|date('c')).diff(now).format('%i') }} minutes ago</span>
  
  {% else %}
  <span>{{ date(time.dateCreated|date('c')).diff(now).format('%h') }} hours ago</span>
  
  {% else %}
  <span>{{ date(time.dateCreated|date('c')).diff(now).format('%d') }} days  agos</span>
  {% 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.
  
  **Tags:** templating, datetime
  
  > **Comments:**
  > **username_1**: Check out the `DateTimeHelper` method `timeAgoInWords`. It will do what you are after.  https://craftcms.com/classreference/helpers/DateTimeHelper#timeAgoInWords-detail  
  > **username_2**: @username_1 Well I learned something today. You should post this as an answer.  
  > **username_3**: Any idea what the Craft 3 version of `timeAgoInWords()` is?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-20. Score: 4
  
  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 }}`
  
  
  ---
  
  