time ago php

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

showing results for - "time ago php"
Benjamín
29 Jan 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
Bertille
19 Jun 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
php get time ago in easy waycanvert from date to 4 days ago 10 minutes agomysql time ago difference1 hour ago phpfunction return time ago phptimestamp show days agotimein one day ago in phpconvert created at time with one minute ago in mysql querytime ago from date phpconvert datetime to time agotime difference html showing agophp ago functionphp days ago from datewhat does php time returncheck days ago timestamp phpphp minute ago timephp display time as hours agophp get time 1 hour agophp get time ago functiontime ago in php php time to string time agocalculate this many minutes ago phpminute ago phpget the time like 2 min ago in phpmysql function min days agofunction return timr ago phpphp get time agotime ago php functionget time ago format phpphp datetime agominutes ago phpsimple time ago phpphp 5 minutes agocompute date time ago in phphours ago to date format mysqlhow much time ago added phpphp datetime a year agoset time ago phpphp time constants day php time 3 year agochange date to number of days ago phpphp time ago from timestamptime ago phpmysql function date to agoweeks ago script phpconvert datetime to time ago phpphp timeagoget days agao in phpcheck days ago timestampseconds ago phpphp code to calculate time agophp time ago functiondays ago in phptime ago with phpphp time format 1 hour agophp time agohow to get time ago in phpdays ago phpphp posted 2 days ago date functionsphp 5 hours agophp get time of agocomvert datetime to timeagophp time ago php convert date to minutes ago1 hour ago in phphow to show seen 19 minutes ago or day ago phpconvert date to one day ago phpphp timestamp 8 days agodate to hourse ago in phpdate difference ago and before php functionphp date agotime ago with date phpdate ago phphow to get ago date in datetime phpphp set hour in datephp check for 1 day agotimestamp time agotimestamp in php agophp date ago functionphp date time to show how many seconds agophp days agophp show time agophp time 5 minutes agoget time ago for database time phpphp convert date to format 1 week agoget time like days agotimestamp to days agophp date hour agophp return time pmphp days agotetimestamp to hours agophp minutes agoget time as 1 day ago in phpconvert date to days ago in phpget time ago php45 min ago and 1 hr ago and 1 day aophp time ago like facebooktime ago dengan datetime phpphp ago timeday ago 2c months ago year ago phpphp agofunction php i minutes agotime ago php