Re: Check time in between times

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Johny Burns" <contactus@xxxxxxxxxxxxxxxx> 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@xxxxxxxxx>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux