note 96247 modified in function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Wed, 17 Feb 2010 14:51:49 +0000 |
| Subject: | note 96247 modified in function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166065@lists.php.net to get a copy of this message | ||
This function calculates if date2 is within an interval of seconds from date1.
<?php
function is_on_interval($date1,$date2,$interval){
$dat2=strtotime($date2);
$dat3=strtotime('+'.$interval.' second '.$date1);
if($dat2>=$dat3){
return false;
}
else
{
return true;
}
}
$date1='2009-08-18 00:02:00';
$date2='2009-08-18 00:05:00';
?>
$date2 is 180 seconds from $date1.
<?php is_on_interval($date1,$date2,'120'); ?>
will return false.
<?php is_on_interval($date1,$date2,'180'); ?>
will return true.
<?php is_on_interval($date1,$date2,'220'); ?>
will return true.
--was--
This function calculates if date2 is within an interval of seconds from date1.
function is_on_interval($date1,$date2,$interval){
$dat2=strtotime($date2);
$dat3=strtotime('+'.$interval.' second '.$date1);
if($dat2>=$dat3){
return false;
}
else
{
return true;
}
}
$date1='2009-08-18 00:02:00';
$date2='2009-08-18 00:05:00';
$date2 is 180 seconds from $date1.
is_on_interval($date1,$date2,'120');
will return false.
is_on_interval($date1,$date2,'180');
will return true.
is_on_interval($date1,$date2,'220');
will return true.
http://php.net/manual/en/function.strtotime.php