Re: Check time in between times
| From: | Emilio Astarita | Date: | Sun, 17 Feb 2008 07:17:28 +0000 |
| Subject: | Re: Check time in between times | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269424@lists.php.net to get a copy of this message | ||
"Johny Burns" <contactus@delivery2you.com> writes:
> I am having fields in my table where I put times like 4:30pm in string
> format
Check this:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html
Perhaps you could use a data type date for that.
> Can anybody help with function which helps detect.
> Is it the current time between those fields?
>
> function checkinzone($time1,$time2):boolean
>
> Has to verify does the current time is in those 2 variables.
This may help you:
function strange2min($strange) {
$h24h = substr($strange,-2);
list($hour,$minute) = preg_split("/(?i:am|pm|:)/",$strange);
if ($h24h == 'am' && $hour == 12) {
$hour = 0;
} elseif ($h24h == 'pm') {
$hour = $hour + 12;
}
return ($hour * 60) + $minute;
}
function checkinzone($start,$end) {
$now = (date('G') * 60) + date('i');
$start = strange2min($start);
$end = strange2min($end);
return ( ($start <= $now ) &&($now <= $end));
}
// test
$start = "1:30am";
$end = "9:39am";
echo '<strong>', var_dump(checkinzone($start,$end)),'</strong>';
--
Emilio Astarita <emilio.astarita@gmail.com>