Reputation: 205
I would like to compare several entries, for which I have the day, month and year saved in separate variables. When I try the following, I do not get the right answer:
$rescount=mysql_query('SELECT COUNT(*) FROM `sdcheckings` WHERE `dchecked` = 1 AND `email` ="'.$_SESSION['email'].'" AND `cday` >'.date('j').' AND `cmonth` >='.date('n').' AND `cyear` >='.date('Y'));
The reason is that this would ignore and entry that is in the following month, but that has a smaller day number. What would be the easiest way to fix this?
Upvotes: 3
Views: 99
Reputation: 205
Here is what works now, thanks!
$rescount=mysql_query('SELECT COUNT(*) FROM `sdcheckings` WHERE `dchecked` = 1 AND `email` ="'.$_SESSION['email'].'" AND DATE(CONCAT_WS("-",`cyear`,`cmonth`,`cday`)) > CURDATE()');
Upvotes: 0
Reputation: 1268
I think that you can use CONCAT_WS
to create date in query
DATE(CONCAT_WS('-',cyear,cmonth,cdate)) AS date
Then you got date in yyyy-mm-dd
format to compare
Upvotes: 2