eval.in

Paste #103106

PHP — PHP 5.5.1, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
function is_diff_bigger($from, $to, $interval) {
	$from = new DateTime($from);
	$to = new DateTime($to);
	$interval = DateInterval::createFromDateString($interval);
	$to->sub($interval);
	return $from <= $to;
}

var_dump( is_diff_bigger('12:00:00', '12:20:00', '30 minutes') );
var_dump( is_diff_bigger('12:00:00', '12:30:00', '30 minutes') );
var_dump( is_diff_bigger('12:00:00', '12:40:00', '30 minutes') );

Program Output

bool(false)
bool(true)
bool(true)

OK (0.008 sec real, 0.007 sec wall, 14 MB, 50 syscalls)

Fork