Re: time question.
| From: | 1LT John W. Holmes | Date: | Fri, 26 Jul 2002 16:42:24 +0000 |
| Subject: | Re: time question. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109789@lists.php.net to get a copy of this message | ||
> How do I compare time in php?
>
> Eg. If I have a mysql time field I retrieve stored in $result[0][0] how do
I
> say :
>
> if (($result[0][0] > $result[0][0] plus ten minutes) && ($result[0][0] >
> '00:00:00')){
MySQL and PHP timestamps are in different formats. MySQL uses YYYYMMDDHHMMSS
and PHP uses a unix timestamp, the number of seconds since January 1st,
1970.
You can use UNIXTIMESTAMP(your_column) in your query to get a PHP style unix
timestamp.
Although, if you explain what you are trying to do a little better, you
could probably do the comparisons a lot easier in your query and not involve
PHP at all.
SELECT * FROM your_table WHERE your_column > your_column + INTERVAL 10
MINUTE AND your_column != 0
That looks equivilent to what you're trying to do in PHP. You might have to
say your_column+0 != 0 to get your_column as an integer and not a string.
---John Holmes...