how to get date difference
-
hi i have 4 fields like as bellow 1.start date 2.start time 3.end date 4.end time by using above fields how can i get difference in hours in php project any body can help me. thank you.
-
hi i have 4 fields like as bellow 1.start date 2.start time 3.end date 4.end time by using above fields how can i get difference in hours in php project any body can help me. thank you.
A little RTFM goes a long way. Open up the PHP manual (online if you were too stupid or lazy to download a free copy) and type "date difference" into the search box. Work with DateTime and DateInterval objects. Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
A little RTFM goes a long way. Open up the PHP manual (online if you were too stupid or lazy to download a free copy) and type "date difference" into the search box. Work with DateTime and DateInterval objects. Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
that is not happening so that only posted.
-
that is not happening so that only posted.
-
hi i have 4 fields like as bellow 1.start date 2.start time 3.end date 4.end time by using above fields how can i get difference in hours in php project any body can help me. thank you.
<?php
$date1 = "2012-10-04 22:45:00";
$date2 = "2013-12-05 13:44:01";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$hours = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
$minuts = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
$seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60));
printf("%d years, %d months, %d days, %d hours, %d minuts\n, %d seconds\n", $years, $months, $days, $hours, $minuts, $seconds);
die;
?> -
hi i have 4 fields like as bellow 1.start date 2.start time 3.end date 4.end time by using above fields how can i get difference in hours in php project any body can help me. thank you.
-
hi i have 4 fields like as bellow 1.start date 2.start time 3.end date 4.end time by using above fields how can i get difference in hours in php project any body can help me. thank you.
If you searched on google you would find 1000's of solutions. this is copied from PHP site
<?php
$td = time_diff($timestamp1-$timestamp2); // has to be a positive result
$td .= ($td=="now")? "":" ago"; // in this example "ago"
echo $td;function time_diff($s){
$time = get\_post\_time('G', true, $post); $s = time() - $time; if($s>=1) { $td = "$s sec"; } if($s>59) { $m = (int)($s/60); $s = $s-($m\*60); // sec left over $td = "$m min"; if($s>1) $td .="s"; } if($m>59){ $hr = (int)($m/60); $m = $m-($hr\*60); // min left over $td = "$hr hr"; if($hr>1) $td .= "s"; if($m>0) $td .= ", $m min"; } if($hr>23){ $d = (int)($hr/24); $hr = $hr-($d\*24); // hr left over $td = "$d day"; if($d>1) $td .= "s"; if($d<3){ if($hr>0) $td .= ", $hr hr"; if($hr>1) $td .= "s"; } } return $td;
}
?>I wish I could believe there is an after life.