function return time ago php

Solutions on MaxInterview for function return time ago php by the best coders in the world

showing results for - "function return time ago php"
Charlie
19 Jun 2016
1public function convert_time_to_days($date) {
2       $current_date = date("Y-m-d H:m:s");
3       $time = array();
4       $day = floor((strtotime($current_date) - strtotime($date)) / (60 * 60 * 24));
5 
6       if ($day == 0) {
7           $hour = floor((strtotime($current_date) - strtotime($date)) / (60 * 60));
8 
9           if ($hour == 0) {
10               $minute = floor((strtotime($current_date) - strtotime($date)) / (60));
11               $time = $minute . __d('course', "minutes ago");
12 
13           } else {
14               $time = $hour . __d('course', "hours ago");
15           }
16      
17       } else {
18           $time = $day . __d('course', "days ago");
19       }
20      
21       return $time;
22   }
23
Lucas
08 Aug 2017
1<!DOCTYPE html>
2<html>
3<body>
4
5<?php
6
7function time_elapsed_string($datetime, $full = false) {
8    $now = new DateTime;
9    $ago = new DateTime($datetime);
10    $diff = $now->diff($ago);
11
12    $diff->w = floor($diff->d / 7);
13    $diff->d -= $diff->w * 7;
14
15    $string = array(
16        'y' => 'year',
17        'm' => 'month',
18        'w' => 'week',
19        'd' => 'day',
20        'h' => 'hour',
21        'i' => 'minute',
22        's' => 'second',
23    );
24    foreach ($string as $k => &$v) {
25        if ($diff->$k) {
26            $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
27        } else {
28            unset($string[$k]);
29        }
30    }
31
32    if (!$full) $string = array_slice($string, 0, 1);
33    return $string ? implode(', ', $string) . ' ago' : 'just now';
34}
35
36echo time_elapsed_string(date("Y-m-d H:i:s", 1621173863));
37?>
38
39</body>
40</html>
41
42  
43 echo time_elapsed_string('2013-05-01 00:22:35');
44echo time_elapsed_string('@1367367755'); # timestamp input
45echo time_elapsed_string('2013-05-01 00:22:35', true);
46
47
48Output :
49
504 months ago
514 months ago
524 months, 2 weeks, 3 days, 1 hour, 49 minutes, 15 seconds ago
queries leading to this page
days ago phpcheck days ago timestamptimestamp to days agotimestamp time agocompute date time ago in phpminutes ago phpminute ago phptimein one day ago in phpdate to hourse ago in phptime ago from time phpfunction return timr ago phpphp convert date to time ago45 min ago and 1 hr ago and 1 day aoset time ago php1 hour ago phpphp time 3 year agophp date hour agophp get time of agophp timestamp 8 days agophp ago functionphp days agotephp datetime one year agophp time ago functionhow to show seen 19 minutes ago or day ago phpget time ago format phphours ago to date format mysqlphp 22datetime 22 minutes agochange date to number of days ago phpconvert datetime to time ago phpconvert datetime to time agoweeks ago script phpconvert created at time with one minute ago in mysql queryconvert date to days ago in phpmysql function date to agophp get time ago function1 hour ago in phpphp posted 2 days ago date functionsget time ago for database time phpdays ago in phpfunction php i minutes agoconvert date to one day ago phpphp time format 1 hour agodate ago phpphp convert date to minutes agophp get time 1 hour agomysql time ago differencefunction return time ago phpcomvert datetime to timeagophp datetime agophp get time agophp ago timecalculate this many minutes ago phpphp date 1 day agotime ago with date phptime ago with phpphp time constants day php time 5 minutes agotime ago from date phpphp date agophp convert date to format 1 week agophp time with am omphp time agophp time ago like facebooktime difference html showing agophp date time to show how many seconds agophp datetime a year agophp time date agotime ago dengan datetime phpphp display time as hours agoshow hours ago time php second to time agos phphow to get ago date in datetime phptimestamp to hours agotime ago in php timestamp in php agocanvert from date to 4 days ago 10 minutes agophp days agophp date two days agophp 5 hours agophp timeagoget the time like 2 min ago in phpphp 5 minutes agotime ago phphow much time ago added phpphp minute ago timephp time ago seconds ago phpphp show time agoget time as 1 day ago in phpphp time ago from timestampphp time to string time agohow to get full date time with secs in phpphp get date 5 minutes agophp format date minutes agotime ago php functionwhat does php time returnsecond to time ago phpdate difference ago and before php functionphp date ago functionget time ago phpphp agomysql function min days agophp check for 1 day agotime ago from timestamp phpphp minutes agophp days ago from datephp return time pmsimple time ago phpget time like days agoget accurate time ago phpcheck days ago timestamp phpday ago 2c months ago year ago phphow to get time ago in phpget days agao in phpphp get time ago in easy wayphp code to calculate time agophp set hour in datetimestamp show days agofunction return time ago php