Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Get PHP Date Time Difference in Days, Hours, Minutes, and Seconds

//get Date diff as intervals 
$d1 = new DateTime("2018-01-10 00:00:00");
$d2 = new DateTime("2019-05-18 01:23:45");
$interval = $d1->diff($d2);
$diffInSeconds = $interval->s; //45
$diffInMinutes = $interval->i; //23
$diffInHours   = $interval->h; //8
$diffInDays    = $interval->d; //21
$diffInMonths  = $interval->m; //4
$diffInYears   = $interval->y; //1

//or get Date difference as total difference
$d1 = strtotime("2018-01-10 00:00:00");
$d2 = strtotime("2019-05-18 01:23:45");
$totalSecondsDiff = abs($d1-$d2); //42600225
$totalMinutesDiff = $totalSecondsDiff/60; //710003.75
$totalHoursDiff   = $totalSecondsDiff/60/60;//11833.39
$totalDaysDiff    = $totalSecondsDiff/60/60/24; //493.05
$totalMonthsDiff  = $totalSecondsDiff/60/60/24/30; //16.43
$totalYearsDiff   = $totalSecondsDiff/60/60/24/365; //1.35
Comment

get hours difference between two dates in php

$hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1);
Comment

php time difference in hours

	date_default_timezone_set("Africa/Johannesburg");
    $now = new DateTime();
    $future_date = new DateTime('2020-10-21 00:00:00');
    
    $interval = $future_date->diff($now);
    
    echo ($interval->format("%a") * 24) + $interval->format("%h"). " hours". $interval->format(" %i minutes ");
    print_r($now->format('Y-m-d H:i:s'));
Comment

php calculate hours and minutes between two times

date_default_timezone_set("Africa/Johannesburg");
    $now = new DateTime();
    $future_date = new DateTime('2020-10-21 00:00:00');
    
    $interval = $future_date->diff($now);
    
    echo ($interval->format("%a") * 24) + $interval->format("%h"). " hours". $interval->format(" %i minutes ");
    print_r($now->format('Y-m-d H:i:s'));
Comment

PREVIOUS NEXT
Code Example
Php :: laravel database connection check 
Php :: php refresh page 
Php :: old function use in checkbox selected in laravel blade 
Php :: laravel model transaction 
Php :: get category name by id wordpress 
Php :: whereyear laravel 
Php :: apache htaccess read from /public 
Php :: how to define variable as object in blade laravel 
Php :: twig symfony get route 
Php :: wordpress logout redirect to home 
Php :: php default timezone 
Php :: php copy url 
Php :: laravel env google smtp 
Php :: Laravel 7 create-project 
Php :: phpstan ignore 
Php :: how to run symfony project 
Php :: add action wp_footer 
Php :: string remove line breaks php 
Php :: php strtotime 
Php :: php convert date from dd/mm/yyyy to yyyy-mm-dd 
Php :: Extract images from a folder in php 
Php :: php get number from string 
Php :: enable shortcodes in text widgets 
Php :: get wordpress id 
Php :: get logged user id laravel 
Php :: add 30 minutes to time in php 
Php :: php merge 2 arrays 
Php :: wordpress disable posts 
Php :: append new line php 
Php :: /laravel-2020-07-27.log" could not be opened 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =