X

PHP check time gap between two times


PHP check time gap between two times. Here we a function to check the time gap between time times, whether the time is lesser than the actual time and vice versa. By using PHP , you  have to check the time gaps, and time differences , Let’s see the code to get idea of working with PHP times.

$working_hours = false;
$kv_time = now();	
$time_now = new DateTime($kv_time);
$start_time= new DateTime('10:00');
$end_time = new DateTime('17:00');

if($time_now> $start_time && $time_now < $end_time) {
	$working_hours = true ; 		
} else {
	$working_hours = false;
}

The above code snippet works to return true or false, if the $kv_time lies inside the Start and End time. it will report as true.

Else it will return you false, The above one will take care of your time gap operations. You can setup some timed operations by using the above code. once if the time is true, this will perform the operations. Else, it will report you as False,

You can use time diff function to find the time gap between two times, but it wont help you to say the time is grater or lesser than the actuall time.

The above one take care of the operations. If you have any bugs and problems drop your comment below.

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Subscribe to our email newsletter.

 

Advertisement

Category Posts