Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

Get total minute and second difference between two dates using php

by
Category:php
php
Get total minute and second difference between two dates using php

This is a simple guide on how to calculate the difference between two dates and get total minute and second in PHP. Be sure to try out the examples below if you’re new to the topic. You may also like How to get year month day difference between two dates using php and Two date get hour and minute using php.

Code

$t1 = strtotime('2018-03-07 10:10:10');
$t2 = strtotime(date('Y-m-d H:i:s'));
$delta_T = abs($t2 - $t1);
$totalminutes = round(((($delta_T % 604800) % 86400)) / 60); 
$totalsec = round((((($delta_T % 604800) % 86400) % 3600) % 60));

$minLen_minit = strlen($totalminutes);
$second       = strlen($totalsec);

if($minLen_minit >= '2'){
    $minutes = $totalminutes;
}else{
    $minutes = '0'.$totalminutes;
}

if($second >= '2'){
    $second_co = $totalsec;
}else{
    $second_co = '0'.$totalsec;
}
echo  $minutes.':'.$second_co;

0 Comments


Html code work in comment box


Related Post