Page 1 of 1

select specific record based on year and month..

Posted: Thu Jun 24, 2004 1:43 am
by kevin7
i've a data column in the table 2004-06-30 (define as date type in mysql)..
now, i want to retrive record that hv year 2004 and month 5 (May)...

the following is the code i've tried to make it work.. but failed..

Code: Select all

$comm = mysql_query("SELECT sal_comm, ord_id FROM sales WHERE emp_id='$emp_id' AND year(sal_date)='2004' AND month(sal_date)='5'");
.... how can i do that...

tq...

Posted: Thu Jun 24, 2004 1:46 am
by feyd
[mysql_man]BETWEEN[/mysql_man] I think..

Posted: Thu Jun 24, 2004 1:53 am
by Illusionist
@feyd, i don't think between will work here.
@kevin7, try adding mysql_error() to find whats wrong, because taht looks right to me....

Code: Select all

$comm = mysql_query("SELECT sal_comm, ord_id FROM sales WHERE emp_id='$emp_id' AND year(sal_date)='2004' AND month(sal_date)='5'") or die(mysql_error());

Posted: Thu Jun 24, 2004 1:56 am
by feyd
true.. that can work too..
hmmm.. looks like bbcode for [mysql_man] isn't working.. bummer..

Posted: Thu Jun 24, 2004 1:58 am
by Illusionist
shucks! I don't think i has worked for quite some time now!