dtyson2000 Posted December 21, 2011 Share Posted December 21, 2011 Hello. Can somebody have a look at this code? I would like it to return birthdays coming in the next three weeks. At the moment as it is, it does this only up to the end of December when it should also be pulling a birthday in the first week of January. I suspect it has something to do with the removal of the "Y"ear in the date formats but I'm not sure because when I add it back in, it returns nothing. The IF line is the suspected culprit. I'm not asking for someone to write code but simply confirm whether or not the issue falls where I suspect it does and maybe a quick explanation of what's wrong. I need to understand this. Thanks! // there is a column in the database called user_dob $user_birthday = date("m-d", strtotime($user_dob)); $curdate = date("m-d"); if ($curdate <= date($user_birthday, strtotime("+21 day"))) { code } Quote Link to comment https://forums.phpfreaks.com/topic/253618-date-comparison-code-assessment/ Share on other sites More sharing options...
scootstah Posted December 21, 2011 Share Posted December 21, 2011 Is user_dob a MySQL time/date/datetime? If yes, you can just use a WHERE clause with MySQL's date functions to find it. Quote Link to comment https://forums.phpfreaks.com/topic/253618-date-comparison-code-assessment/#findComment-1300145 Share on other sites More sharing options...
dtyson2000 Posted December 21, 2011 Author Share Posted December 21, 2011 It is indeed a date field in the database. Perhaps that is a better tach than trying to do it with PHP, although I'm sure there's a PHP solution as well. Thanks for the input! Quote Link to comment https://forums.phpfreaks.com/topic/253618-date-comparison-code-assessment/#findComment-1300150 Share on other sites More sharing options...
scootstah Posted December 21, 2011 Share Posted December 21, 2011 There is a PHP solution, but you are then doing unnecessary formatting because the database can handle it just fine. Quote Link to comment https://forums.phpfreaks.com/topic/253618-date-comparison-code-assessment/#findComment-1300156 Share on other sites More sharing options...
dtyson2000 Posted December 22, 2011 Author Share Posted December 22, 2011 Wanted to drop in and thank you again for suggesting that there is a MySQL solution. I've taken care of the entire thing that way. So it's all set. Thanks, again! Quote Link to comment https://forums.phpfreaks.com/topic/253618-date-comparison-code-assessment/#findComment-1300463 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.