-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.php
47 lines (36 loc) · 1.41 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require_once 'admin/config/config.php';
$user_id= filter_input(INPUT_GET, 'user');
//$time_elapsed = timeAgo($time_ago); //The argument $time_ago is in timestamp (Y-m-d H:i:s)format.
//Function definition
function timeAgo($time_ago) {
$time_ago = strtotime($time_ago) ? strtotime($time_ago) : $time_ago;
$time = time() - $time_ago;
switch($time):
// seconds
case $time <= 60;
return 'lessthan a minute ago';
// minutes
case $time >= 60 && $time < 3600;
return (round($time/60) == 1) ? 'a minute' : round($time/60).' minutes ago';
// hours
case $time >= 3600 && $time < 86400;
return (round($time/3600) == 1) ? 'a hour ago' : round($time/3600).' hours ago';
// days
case $time >= 86400 && $time < 604800;
return (round($time/86400) == 1) ? 'a day ago' : round($time/86400).' days ago';
// weeks
case $time >= 604800 && $time < 2600640;
return (round($time/604800) == 1) ? 'a week ago' : round($time/604800).' weeks ago';
// months
case $time >= 2600640 && $time < 31207680;
return (round($time/2600640) == 1) ? 'a month ago' : round($time/2600640).' months ago';
// years
case $time >= 31207680;
return (round($time/31207680) == 1) ? 'a year ago' : round($time/31207680).' years ago' ;
endswitch;
}
$updated = $db->rawQueryValue ("SELECT updated_at FROM usagedetails WHERE id=".$user_id." limit 1", 'limit 1');
echo "Updated ".timeAgo($updated)."<br>";
echo $updated;
?>