-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatediff.php
112 lines (108 loc) · 2.04 KB
/
datediff.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/* Date/Time Interval Calculator
By Ewere Diagboya, 15-Oct-2013 12:23pm
=================
|| Description ||
=================
This is a simple code which helps to give the difference between two date time strings. The current values have a difference of 1yr. But changing any of the values in days months year will give the appropriate difference to the nearest highest value
*/
$time1 = strtotime('2013-05-14 11:50:00');
$time2 = strtotime('2012-05-14 11:50:00');
$interval = $time1 - $time2; // Interval in Seconds
// Display in Secs
if($interval < 60)
{
if($interval > 1)
{
echo $interval."secs";
}
else
{
echo $interval . "sec";
}
}
// Convert to Mins
else if($interval >= 60 && $interval < 3600)
{
$newinterval = $interval / 60;
$newinterval = round($newinterval);
if($newinterval > 1)
{
echo $newinterval."mins";
}
else
{
echo $newinterval . "min";
}
}
// Convert to Hours
else if($interval >= 3600 && $interval < 86400)
{
$newinterval = $interval / 3600;
$newinterval = round($newinterval);
if($newinterval > 1)
{
echo $newinterval."hrs";
}
else
{
echo $newinterval . "hr";
}
}
// Convert to Days
else if($interval >= 86400 && $interval < 604800)
{
$newinterval = $interval / 86400;
$newinterval = round($newinterval);
if($newinterval > 1)
{
echo $newinterval."days";
}
else
{
echo $newinterval . "day";
}
}
// Convert to Weeks
else if($interval >= 604800 && $interval < 2419200)
{
$newinterval = $interval / 604800;
$newinterval = ceil($newinterval);
if($newinterval > 1)
{
echo $newinterval."wks";
}
else
{
echo $newinterval . "wk";
}
}
// Convert to Months
else if($interval >= 2419200 && $interval < 29030400)
{
$newinterval = $interval / 2419200;
$newinterval = ceil($newinterval);
if($newinterval > 1)
{
echo $newinterval."mths";
}
else
{
echo $newinterval . "mth";
}
}
// Convert to Years
else if($interval >= 29030400)
{
$newinterval = $interval / 29030400;
$newinterval = round($newinterval);
if($newinterval > 1)
{
echo $newinterval."yrs";
}
else
{
echo $newinterval . "yr";
}
}
?>