{"id":1243,"date":"2013-07-08T09:38:30","date_gmt":"2013-07-08T09:38:30","guid":{"rendered":"http:\/\/www.websitedesignwebsitedevelopment.com\/?p=1243"},"modified":"2014-03-19T09:13:39","modified_gmt":"2014-03-19T09:13:39","slug":"php-function-time-difference-or-time-ago","status":"publish","type":"post","link":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/","title":{"rendered":"PHP Function &#8211; Time Difference or Time Ago"},"content":{"rendered":"<h2>PHP Function &#8211; Time Difference or Time Ago<\/h2>\n<p><code>function _ago($time_to, $time_from = 0) {<br \/>\nif($time_from==0) time();<br \/>\n$rtc = 60*60*24; \/\/ROUND THE CLOCK<br \/>\n$total_weeks = 52.177457; \/\/ESTIMATE NO. OF WEEKS<br \/>\n$years = (int)((($time_from - $time_to)\/(7*$rtc))\/$total_weeks);<br \/>\n$rem = (int)(($time_from-$time_to)-($years * $total_weeks * 7 * $rtc));<br \/>\n$weeks = (int)(($rem)\/(7*$rtc));<br \/>\n$days = (int)(($rem)\/$rtc) - $weeks*7;<br \/>\n$hours = (int)(($rem)\/3600) - $days*24 - $weeks*7*24;<br \/>\n$mins = (int)(($rem)\/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;<br \/>\n$output = '';<br \/>\nif($years==1) $output .= \"$years year, \";<br \/>\nif($years&gt;1) $output .= \"$years years, \";<br \/>\nif($weeks==1) $output .= \"$weeks week, \";<br \/>\nif($weeks&gt;1) $output .= \"$weeks weeks, \";<br \/>\nif($days==1) $output .= \"$days day,\";<br \/>\nif($days&gt;1) $output .= \"$days days,\";<br \/>\nif($hours == 1) $output .= \" $hours hour and\";<br \/>\nif($hours&gt;1) $output .= \" $hours hours and\";<br \/>\nif($mins == 1) $output .= \" 1 minute\";<br \/>\nelse $output .= \" $mins minutes\";<br \/>\nreturn $output;<br \/>\n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP Function &#8211; Time Difference or Time Ago function _ago($time_to, $time_from = 0) { if($time_from==0) time(); $rtc = 60*60*24; \/\/ROUND THE CLOCK $total_weeks = 52.177457; \/\/ESTIMATE NO. OF WEEKS $years = (int)((($time_from &#8211; $time_to)\/(7*$rtc))\/$total_weeks); $rem = (int)(($time_from-$time_to)-($years * $total_weeks * 7 * $rtc)); $weeks = (int)(($rem)\/(7*$rtc)); $days = (int)(($rem)\/$rtc) &#8211; $weeks*7; $hours = (int)(($rem)\/3600) &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1328,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-helper-functions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP Function - Time Difference or Time Ago<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Function - Time Difference or Time Ago\" \/>\n<meta property=\"og:description\" content=\"PHP Function &#8211; Time Difference or Time Ago function _ago($time_to, $time_from = 0) { if($time_from==0) time(); $rtc = 60*60*24; \/\/ROUND THE CLOCK $total_weeks = 52.177457; \/\/ESTIMATE NO. OF WEEKS $years = (int)((($time_from - $time_to)\/(7*$rtc))\/$total_weeks); $rem = (int)(($time_from-$time_to)-($years * $total_weeks * 7 * $rtc)); $weeks = (int)(($rem)\/(7*$rtc)); $days = (int)(($rem)\/$rtc) - $weeks*7; $hours = (int)(($rem)\/3600) - [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\" \/>\n<meta property=\"og:site_name\" content=\"AndroidBubble Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453\" \/>\n<meta property=\"article:published_time\" content=\"2013-07-08T09:38:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-19T09:13:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"403\" \/>\n\t<meta property=\"og:image:height\" content=\"403\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fahad\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fahad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\"},\"author\":{\"name\":\"Fahad\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"headline\":\"PHP Function &#8211; Time Difference or Time Ago\",\"datePublished\":\"2013-07-08T09:38:30+00:00\",\"dateModified\":\"2014-03-19T09:13:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\"},\"wordCount\":16,\"image\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg\",\"articleSection\":[\"Helper Functions\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\",\"url\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\",\"name\":\"PHP Function - Time Difference or Time Ago\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg\",\"datePublished\":\"2013-07-08T09:38:30+00:00\",\"dateModified\":\"2014-03-19T09:13:39+00:00\",\"author\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"breadcrumb\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage\",\"url\":\"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg\",\"contentUrl\":\"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg\",\"width\":403,\"height\":403},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/androidbubble.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Website Development\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Frameworks\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"CodeIgniter\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/codeigniter\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Helper Functions\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/codeigniter\/helper-functions\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"PHP Function &#8211; Time Difference or Time Ago\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\",\"url\":\"https:\/\/androidbubble.com\/blog\/\",\"name\":\"AndroidBubble Blog\",\"description\":\"Articles &amp; Posts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/androidbubble.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\",\"name\":\"Fahad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"caption\":\"Fahad\"},\"sameAs\":[\"http:\/\/www.androidbubbles.com\/\",\"https:\/\/x.com\/phpFlex\"],\"url\":\"https:\/\/androidbubble.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Function - Time Difference or Time Ago","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/","og_locale":"en_US","og_type":"article","og_title":"PHP Function - Time Difference or Time Ago","og_description":"PHP Function &#8211; Time Difference or Time Ago function _ago($time_to, $time_from = 0) { if($time_from==0) time(); $rtc = 60*60*24; \/\/ROUND THE CLOCK $total_weeks = 52.177457; \/\/ESTIMATE NO. OF WEEKS $years = (int)((($time_from - $time_to)\/(7*$rtc))\/$total_weeks); $rem = (int)(($time_from-$time_to)-($years * $total_weeks * 7 * $rtc)); $weeks = (int)(($rem)\/(7*$rtc)); $days = (int)(($rem)\/$rtc) - $weeks*7; $hours = (int)(($rem)\/3600) - [&hellip;]","og_url":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/","og_site_name":"AndroidBubble Blog","article_publisher":"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453","article_published_time":"2013-07-08T09:38:30+00:00","article_modified_time":"2014-03-19T09:13:39+00:00","og_image":[{"width":403,"height":403,"url":"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg","type":"image\/jpeg"}],"author":"Fahad","twitter_misc":{"Written by":"Fahad","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#article","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/"},"author":{"name":"Fahad","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"headline":"PHP Function &#8211; Time Difference or Time Ago","datePublished":"2013-07-08T09:38:30+00:00","dateModified":"2014-03-19T09:13:39+00:00","mainEntityOfPage":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/"},"wordCount":16,"image":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage"},"thumbnailUrl":"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg","articleSection":["Helper Functions"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/","url":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/","name":"PHP Function - Time Difference or Time Ago","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage"},"image":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage"},"thumbnailUrl":"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg","datePublished":"2013-07-08T09:38:30+00:00","dateModified":"2014-03-19T09:13:39+00:00","author":{"@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"breadcrumb":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#primaryimage","url":"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg","contentUrl":"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg","width":403,"height":403},{"@type":"BreadcrumbList","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/codeigniter\/helper-functions\/php-function-time-difference-or-time-ago\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/androidbubble.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Website Development","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/"},{"@type":"ListItem","position":3,"name":"PHP Frameworks","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/"},{"@type":"ListItem","position":4,"name":"CodeIgniter","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/codeigniter\/"},{"@type":"ListItem","position":5,"name":"Helper Functions","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/codeigniter\/helper-functions\/"},{"@type":"ListItem","position":6,"name":"PHP Function &#8211; Time Difference or Time Ago"}]},{"@type":"WebSite","@id":"https:\/\/androidbubble.com\/blog\/#website","url":"https:\/\/androidbubble.com\/blog\/","name":"AndroidBubble Blog","description":"Articles &amp; Posts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/androidbubble.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7","name":"Fahad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","caption":"Fahad"},"sameAs":["http:\/\/www.androidbubbles.com\/","https:\/\/x.com\/phpFlex"],"url":"https:\/\/androidbubble.com\/blog\/author\/admin\/"}]}},"views":742,"jetpack_featured_media_url":"https:\/\/androidbubble.com\/blog\/wp-content\/uploads\/2013\/07\/wdwd-study.jpg","_links":{"self":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/1243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/comments?post=1243"}],"version-history":[{"count":3,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/1243\/revisions"}],"predecessor-version":[{"id":1329,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/1243\/revisions\/1329"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/media\/1328"}],"wp:attachment":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/media?parent=1243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/categories?post=1243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/tags?post=1243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}