Logo

Office Address

123/A, Miranda City Likaoli
Prikano, Dope

Phone Number

+0989 7876 9865 9

+(090) 8765 86543 85

Email Address

info@example.com

example.mail@hum.com

PHP Code Check time difference is between two time slots

We are going to explain how to get the time difference between timeslots. below are the simple example given to get the time difference between the two given slots. As you can see we have used the inbuilt function DateTime::createFromFormat() or strtotime() of PHP to parse the time string according to the required format it returns the result.  


Below are the simple example in PHP to get the time diffrence between time slots 

<?php

function checkIfExist($fromTime, $toTime, $input) {
    
    $fromDateTime = DateTime::createFromFormat("!H:i", $fromTime);    
    $toDateTime = DateTime::createFromFormat('!H:i', $toTime);
    $inputDateTime= DateTime::createFromFormat('!H:i', $input);
    if ($fromDateTime> $toDateTime) $toDateTime->modify('+1 day');
    return ($fromDateTime <= $inputDateTime&& $inputDateTime<= $toDateTime) || ($fromDateTime <= $inputDateTime->modify('+1 day') && $inputDateTime<= $toDateTime);
}

$result=checkIfExist("08:00","18:00","09:00");
echo $result; // Result 1 - true

?>

The second possible way to get the time difference between time slots below are the given sample 

Getting the time difference between two time slots in PHP, You can use strtotime() for time calculation. Based on your requirement you can customize the script. 
Here is another simple example in PHP to get the time difference between time slots: 
<?php
  $checkTime = strtotime('09:00:59');
  echo 'Check Time : date('H:i:s');
  echo strtotime('2013-03-30 21:00') - strtotime('2013-03-29 21:00'); 
  echo strtotime('2013-03-31 21:00') - strtotime('2013-03-30 21:00'); 
  //Result  you get 86400 and 82800.
?>

Tags

  • How to check if time is between two times in PHP

  • Check if time is between two times moment

  • Check the time between two times in laravel

  • PHP if the current time is between
  • Check if time is between two times moment
  • PHP calculate the time difference between two dates in hours and minutes

  • PHP Code to get a time difference

Related Posts

Advantages and Disadvantages of Choosing WordPress as Your CMS Solution

Advantages and Disadvantages of Choosing WordPress as Your CMS Solution

In the digital age, selecting the right Content Management System (CMS) is crucial for businesses aiming to establish a strong online presence. WordPress, a leading CMS, powers over 40% of websites gl

Read More
O

Outsource And Offshore Testing Company India

Blazingcoders an Outsource and Offshore testing company in India provides various options in Software testing like Functional testing, Mobile testing, Performance testing, End to end testing, Au

Read More
How to Create Custom Post type without a plugin?

How to Create Custom Post type without a plugin?

WordPress is a beat Content management System website that provides more than a blog. Users can create any type of website with the WordPress CMS. In WordPress, the most powerful feature is custom pos

Read More