Ways of searching by relative dates and times in MySQL

Discussion in 'MySQL' started by RootShell, Jul 12, 2007.

  1. #1
    I'm using some queries in MySQL where I'm looking at data lying within certain time ranges.

    I've learned about NOW(), but are there similar commands for looking up times in the past or future?

    Right now I'm using the following structure:

    $query=mysql_query("SELECT * FROM table WHERE created>='".date("Y-m-d H:i:s",time()-1800)."'");

    Also, if I wanted to look up data that meets one requirement and one and/or the other of the a second requirement, can I use the following structure:

    SELECT * FROM table WHERE x='$x' AND (y='$y' ¦¦ z='$z')

    It seems to work for me, but I just wanted to make sure I'm not opening room for a bug or performance issues.

    Thanks.
     
    RootShell, Jul 12, 2007 IP