chewie Posted November 18, 2009 Share Posted November 18, 2009 Question: How do I compare a php generated date (y-m-d) to a DATE from Mysql?? I'm sure this has to be simpler than I'm approaching it as. Basically I've already made a call to a database and table where I retrieve a field called expiredate. I then want to compare it against today's date, and see if it equals today's date or is greater than... I would think that I could do this simply by: $expiredate = $row['expiredate']; $currentdate = date("Y-m-d"); if($expiredate >= $currentdate) {.........} Of course this does not appear to work. What am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/ Share on other sites More sharing options...
Ken2k7 Posted November 18, 2009 Share Posted November 18, 2009 Is the column expiredate set to a date format? Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-960429 Share on other sites More sharing options...
chewie Posted November 19, 2009 Author Share Posted November 19, 2009 Yes it is. Set specifically to type DATE. Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-960986 Share on other sites More sharing options...
PFMaBiSmAd Posted November 19, 2009 Share Posted November 19, 2009 The code you implied in the first post should work if $row['expiredate'] actually contains a DATE value. What symptom did you get that makes you think it did not work? If you are trying to retrieve only rows WHERE expiredate is greater-than or equal to todays date, you would do that directly in your query using a WHERE clause - .... WHERE expiredate >= CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-960990 Share on other sites More sharing options...
chewie Posted November 19, 2009 Author Share Posted November 19, 2009 Effectively when the code reaches that point in its execution i get a blank white page instead of the message I prescribed to be echo'd at that point. Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-960993 Share on other sites More sharing options...
JonnoTheDev Posted November 19, 2009 Share Posted November 19, 2009 Effectively when the code reaches that point in its execution i get a blank white page instead of the message I prescribed to be echo'd at that point. You have an error! Switch error reporting on. <?php // top of page ini_set('display_errors', 1); ini_set('error_reporting', E_ALL & ~E_NOTICE); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-960995 Share on other sites More sharing options...
chewie Posted November 19, 2009 Author Share Posted November 19, 2009 Amazingly, error logging is enabled and nothing is outputted! That includes Zend's logg files for PHP and itself as well. Tried this all on XAMP as well, same deal-y-o. Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-961015 Share on other sites More sharing options...
FaT3oYCG Posted November 19, 2009 Share Posted November 19, 2009 try: $expiredate = strtotime($row['expiredate']); $currentdate = strtotime(date("Y-m-d")); if($expiredate >= $currentdate) {.........} so they are in the same format. Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-961025 Share on other sites More sharing options...
chewie Posted November 19, 2009 Author Share Posted November 19, 2009 Same outcome, blank screen, no errors, etc. *Scratching head* Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-961046 Share on other sites More sharing options...
PFMaBiSmAd Posted November 19, 2009 Share Posted November 19, 2009 Blank pages are usually due to fatal parse errors. You would need to set the error_reporting/display_errors settings in your master php.ini (and confirm that the settings are actually changed using a phpinfo() statement) in order to have php report and display fatal parse errors. If your code is actually executing but is not producing any output, you would need to post your actual code if you want someone else to help determine what is causing the symptom. We cannot help with something without seeing it and there is not one 'fix' for any specific symptom because 10,000 different people could have written this thread and there could be something different wrong with each of their programs that are producing the same symptom. You also need to set error_reporting to E_ALL because hiding notice messages would more than likely hide the reason why your code is not doing what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-961051 Share on other sites More sharing options...
chewie Posted November 19, 2009 Author Share Posted November 19, 2009 Haha, if I thought about things correctly, I would have probably caught this sooner =) $currentdate >= $expiredate Really should be looking at..hmm is TODAY's date greater than or equal to whats in the system? Der me, lol. Now to get this conditional working.. $expires == 'yes' && $currentdate >= $expiredate Didn't this use to work with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-961061 Share on other sites More sharing options...
chewie Posted November 19, 2009 Author Share Posted November 19, 2009 *chewie needs to re-read the PHP manual LMAO. how about the general 'and' in betwixt eh? Everything is working as intended, so thanks for the assistance. Now to hit the manual Quote Link to comment https://forums.phpfreaks.com/topic/182068-solved-how-do-i-compare-a-php-generated-date-y-m-d-to-a-date-from-mysql/#findComment-961093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.