Re: easier way to do this? (time interval)

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

 



Hi,

convert your date to UNIX_TIMESTAMP, which is number of seconds since
1.1.1970, and you can use simple math, as in

  $query=mysql_query("
    SELECT dtg 
    FROM techs 
    WHERE 
      tech='$user'
    AND
      UNIX_TIMESTAMP(dtg) > UNIX_TIMESTAMP(NOW()) - 86400 
    AND
      HOUR(dtg)>=7
  ");
... where 86400 = 24 hours (in seconds)

See <http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1302>


Thomas


> -----Ursprüngliche Nachricht-----
> Von: Thoenen, Peter Mr. EPS
> [mailto:Peter.Thoenen@bondsteel2.areur.army.mil]
> Gesendet: Freitag, 11. Oktober 2002 06:34
> An: php-db@lists.php.net
> Betreff:  easier way to do this? (time interval)
> 
> 
> 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
> 

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



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux