{"id":1709507,"date":"2010-10-07T08:46:09","date_gmt":"2010-10-07T08:46:09","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/human-time-difference-edit\/"},"modified":"2016-08-19T19:55:51","modified_gmt":"2016-08-19T19:55:51","slug":"human-time-difference-edit","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/human-time-difference-edit\/","title":{"rendered":"Human time Difference edit?"},"content":{"rendered":"<p>I was just discovering that wordpress actually has a &#8216;time ago&#8217; (human time difference) function. But I wondered if it could be edited in some way. <\/p>\n<p>Because once your posts (and comments) become years old, rather than days, then its more confusing to view &#8220;1268 days ago&#8221; instead of simply the date.<\/p>\n<p>I wonder if anyone can help me (or tell me how) if its possible to manage to get it to show &#8220;weeks ago&#8221;, &#8220;months ago&#8221; or even &#8220;years ago&#8221;.<\/p>\n<p>PS. Im somewhat of a newbie in PHP coding.<\/p>\n<pre><code>\/**\n * Determines the difference between two timestamps.\n *\n * The difference is returned in a human readable format such as &quot;1 hour&quot;,\n * &quot;5 mins&quot;, &quot;2 days&quot;.\n *\n * @since 1.5.0\n *\n * @param int $from Unix timestamp from which the difference begins.\n * @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.\n * @return string Human readable time difference.\n *\/\nfunction human_time_diff( $from, $to = &#039;&#039; ) {\n\tif ( empty($to) )\n\t\t$to = time();\n\t$diff = (int) abs($to - $from);\n\tif ($diff &lt;= 3600) {\n\t\t$mins = round($diff \/ 60);\n\t\tif ($mins &lt;= 1) {\n\t\t\t$mins = 1;\n\t\t}\n\t\t\/* translators: min=minute *\/\n\t\t$since = sprintf(_n(&#039;%s min&#039;, &#039;%s mins&#039;, $mins), $mins);\n\t} else if (($diff &lt;= 86400) &amp;&amp; ($diff &gt; 3600)) {\n\t\t$hours = round($diff \/ 3600);\n\t\tif ($hours &lt;= 1) {\n\t\t\t$hours = 1;\n\t\t}\n\t\t$since = sprintf(_n(&#039;%s hour&#039;, &#039;%s hours&#039;, $hours), $hours);\n\t} elseif ($diff &gt;= 86400) {\n\t\t$days = round($diff \/ 86400);\n\t\tif ($days &lt;= 1) {\n\t\t\t$days = 1;\n\t\t}\n\t\t$since = sprintf(_n(&#039;%s day&#039;, &#039;%s days&#039;, $days), $days);\n\t}\n\treturn $since;\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-1709507","topic","type-topic","status-closed","hentry","topic-tag-difference","topic-tag-human","topic-tag-time"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/1709507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/1709507\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=1709507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}