arunkar Posted March 28, 2008 Share Posted March 28, 2008 Hi, I'm very new to PHP. I'm trying count the number of registrations today and display in the web page. Below is the code I'm using but I'm unable to compare: The date is the mysql database is stored as 2008-03-27 21:09:41 $today = date("Y-m-d"); $resultCount = mysql_query("SELECT count(*) FROM users WHERE registerDate='$today' "); its returning 0 but there are 2 registrations. So there is a logical error. I'm using the date functions here: http://sg2.php.net/date for reference. Any ideas? ??? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/98272-simple-php-date-comparison/ Share on other sites More sharing options...
ryeman98 Posted March 28, 2008 Share Posted March 28, 2008 $today = date("Y-m-d"); $resultCount = mysql_query("SELECT count(*) FROM users WHERE registerDate='$today' "); Try changing it to: $today = date("Y-m-d"); $resultCount = mysql_query("SELECT count(*) FROM users WHERE registerDate='$today*' "); Link to comment https://forums.phpfreaks.com/topic/98272-simple-php-date-comparison/#findComment-502852 Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2008 Share Posted March 28, 2008 Your field in the database is a DATETIME type. If you want to compare just the date, then your query must reference just the date (the mysql DATE() function will work.) Also, it is not necessary to use any slow php code to form today's date, just use the mysql CURDATE() function - $resultCount = mysql_query("SELECT count(*) FROM users WHERE DATE(registerDate) = CURDATE()"); Link to comment https://forums.phpfreaks.com/topic/98272-simple-php-date-comparison/#findComment-502874 Share on other sites More sharing options...
arunkar Posted March 28, 2008 Author Share Posted March 28, 2008 Thanks PFMaBiSmAd it worked like a jem! Thanks ryeman98, it did not work though... cheers Link to comment https://forums.phpfreaks.com/topic/98272-simple-php-date-comparison/#findComment-502900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.