Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

different between two dates

<?php
$date2='2022-08-1 2:10:00';
date_default_timezone_set('Asia/Karachi');
    $date1 = date("Y-m-d H:i:s");
    $timestamp1 = strtotime($date1);
    $timestamp2 = strtotime($date2);
    $posted_time_hours  = round((abs($timestamp2 - $timestamp1))/(60*60)) ;
    if(($posted_time_hours) >= 24){ 
        $posted_time_hours = round($posted_time_hours/24) . " day(s) ago";
    }
    else{

         $posted_time_hours =  $posted_time_hours . " hour(s) ago";
    }
    echo $posted_time_hours;
?>
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #dates
ADD COMMENT
Topic
Name
1+1 =