hey people,

Im trying to do this:

$id = '2006-05';

$query = "select * from $TableName where Date LIKE $id order by id DESC";

The Date field is formatted as DATE and id like to pull out the entrys where the DATE is like the id for example: 2006-05 which is the year and month.

Is this not possible the way im trying to do it or am I getting the above code wrong?

should I be trying something like this instead:

$query = "SELECT * FROM $TableName WHERE $id LIKE DATE_FORMAT(Date,'%M %Y') ORDER BY 'Date' DESC";

Any help is welcome, thanks.

    I haven't tested this, but try a SQL query like this:

    $query = "select * from $TableName where Date LIKE \"$id%\" order by id DESC";   

    The % is the wildcard character for SQL. I think this assumes your Date column is not a date or time type but an int or text type, but I'm not 100% sure.

      maybe this:

       $id_low = '2006-05-01';
      $id_high = '2006-05-31';
      
      $query = "select * from $TableName where Date >$id_low AND Date<$id_high order by id DESC"; 
      

        Thanks people, perfect help.

        Ended up using this:

        $id_low = $id.'-01'; 
        $id_high = $id.'-31'; 
        
        $query = "select * from $TableName where Date >= \"%$id_low%\" AND Date <= \"%$id_high%\" order by id DESC";
        
          Write a Reply...