-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_conversion.php
More file actions
75 lines (57 loc) · 2.31 KB
/
Copy pathtime_conversion.php
File metadata and controls
75 lines (57 loc) · 2.31 KB
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
<?php
// $d1="2021-04-08 22:45:00";
// $d2="2021-04-08 10:44:01";
function time_operation($heure_envoie,$heure_reception)
{
$date1 = strtotime($heure_envoie);
$date2 = strtotime($heure_reception);
// Formulate the Difference between two dates
$diff = abs($date2 - $date1);
// To get the year divide the resultant date into
// total seconds in a year (365*60*60*24)
$years = floor($diff / (365*60*60*24));
// To get the month, subtract it with years and
// divide the resultant date into
// total seconds in a month (30*60*60*24)
$months = floor(($diff - $years * 365*60*60*24)
/ (30*60*60*24));
// To get the day, subtract it with years and
// months and divide the resultant date into
// total seconds in a days (60*60*24)
$days = floor(($diff - $years * 365*60*60*24 -
$months*30*60*60*24)/ (60*60*24));
// To get the hour, subtract it with years,
// months & seconds and divide the resultant
// date into total seconds in a hours (60*60)
$hours = floor(($diff - $years * 365*60*60*24
- $months*30*60*60*24 - $days*60*60*24)
/ (60*60));
// To get the minutes, subtract it with years,
// months, seconds and hours and divide the
// resultant date into total seconds i.e. 60
$minutes = floor(($diff - $years * 365*60*60*24
- $months*30*60*60*24 - $days*60*60*24
- $hours*60*60)/ 60);
// To get the minutes, subtract it with years,
// months, seconds, hours and minutes
$seconds = floor(($diff - $years * 365*60*60*24
- $months*30*60*60*24 - $days*60*60*24
- $hours*60*60 - $minutes*60));
// Print the result
if($years==0 && $months==0 && $days==0)
{
return $hours.":".$minutes.":".$seconds;
}
elseif($years==0 && $months==0)
{
return $days."d ".$hours.":".$minutes.":".$seconds;
}
elseif($years==0)
{
return $months."months ".$days."days ".$hours.":".$minutes.":".$seconds;
}
else{
return $years."years".$months."months".$days."days".$hours.":".$minutes.":".$seconds;
}
}
?>