หาผลต่างของวันเวลา ด้วย PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function get_datetime_diff($datetime_start,$datetime_end) { $seconds = strtotime($datetime_end) - strtotime($datetime_start); $days = floor($seconds / 86400); $hours = floor(($seconds - ($days * 86400)) / 3600); $minutes = floor(($seconds - ($days * 86400) - ($hours * 3600))/60); $seconds = floor(($seconds - ($days * 86400) - ($hours * 3600) - ($minutes*60))); $str = ''; if($days>0){ $str .= $days." Days "; } if($hours>0){ $str .= $hours." Hours "; } if($minutes>0){ $str .= $minutes." Minutes "; } echo $str.$seconds." Seconds"; } |
วิธีใช้งาน
1 |
get_datetime_diff('2016-02-02 07:34:11','2016-03-02 05:32:08'); |
ผลลัพธ์
28 Days 21 Hours 57 Minutes 57 Seconds