RE: [PHP-DB] Re: easier way to do this? (time interval)
| From: | Snijders, Mark | Date: | Fri, 11 Oct 2002 10:24:08 +0000 |
| Subject: | RE: [PHP-DB] Re: easier way to do this? (time interval) | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22340@lists.php.net to get a copy of this message | ||
maybe i dont get the question,
but for all records for the last 24 hours (1 day) i use:
this is an insteresting page:
http://www.mysql.com/doc/en/Date_and_time_functions.html
i says:
Here is an example that uses date functions. The following query selects all
records with a date_col value from within the last 30 days:
mysql> SELECT something FROM tbl_name
WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;
so for 24 hours... change the 30 in 1 :) is this what you mean?
bye,
mark snijders
-----Original Message-----
From: David Robley [mailto:robleyd@paradise.net.nz]
Sent: vrijdag 11 oktober 2002 12:23
To: php-db@lists.php.net
Subject: [PHP-DB] Re: easier way to do this? (time interval)
In article
<A733FF9B1FB0F441B3A6209FF71030E501065A00@bondsteel2.areur.army.mil>,
Peter.Thoenen@bondsteel2.areur.army.mil says...
> Hello,
>
> Curious if there is an easier way to do this (using just SQL and not PHP).
> SQL seems powerful enough to do this but can't think of the synatx. Note,
I
> am using MySQL so no sub-selects (or other useful items). Basically
trying
> to pull all records for a 24 hour period but instead of 0000->2400,
> 0700->0700 (next day).
>
> if (date("H")>7){
>
> $query=mysql_query("
> SELECT dtg
> FROM techs
> WHERE
> tech='$user'
> AND
> DAYOFMONTH(NOW())=DAYOFMONTH(dtg)
> AND
> HOUR(dtg)>=7
> ");
>
> } else {
>
> $query=mysql_query("
> SELECT dtg
> FROM techs
> WHERE
> tech='$user'
> AND
> (
> (DAYOFMONTH(NOW())=DAYOFMONTH(dtg) AND HOUR(dtg)<7)
> OR
> ((DAYOFMONTH(NOW())-1)=DAYOFMONTH(dtg) AND HOUR(dtg)>=7)
> )
> ");
>
> }
>
> Cheers,
>
> -peter
I'd imagine that with a judicious use of mysql's IF statement and
HOUR(NOW()) you could do pretty much what you want. I can't be hanged
going through the docs right now, or I'd have a try at the syntax for you
:-)
--
David Robley
Temporary Kiwi!
Quod subigo farinam
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php