doubledee Posted April 3, 2011 Share Posted April 3, 2011 I am trying to check if a credit card has expired. My criterion is whether or not the date submitted is prior to this month if the year matches 2011. // Check for Expired Card. if (($expYear = date('Y')) && ($expMonth < date('M'))){ $errors['expDate'] = 'Expiration Date cannot be in the past.'; } Why is this not working? I chose March 2011 and it fails. In fact, it fails for any date?! Debbie Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/ Share on other sites More sharing options...
Pikachu2000 Posted April 3, 2011 Share Posted April 3, 2011 if (($expYear == date('Y')) Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/#findComment-1196099 Share on other sites More sharing options...
doubledee Posted April 3, 2011 Author Share Posted April 3, 2011 if (($expYear == date('Y')) Good catch. I always seem to make that mistake! Unfortunately, that didn't fix my problem. Here is my code again... // Check for Expired Card. if (($expYear == date('Y')) && ($expMonth < date('M'))){ // if (($expYear == '2011') && ($expMonth < '04')){ $errors['expDate'] = 'Expiration Date cannot be in the past.'; }else{ $expMonth = $_POST['expMonth']; $expYear = $_POST['expYear']; } If I choose May 2011 (i.e. "05" "2011") them my code take the THEN path above and goes to the line... $errors['expDate'] = 'Expiration Date cannot be in the past.'; When I put in hard-coded values of "2011" and "04" then the code works?! So something is probably wrong with these two statements... == date('Y')) and < date('M'))) Also, when I stepped through my code in NetBeans, the values I selected in my drop-down menus (i.e. "05" and "2011") were getting assigned to variables like you'd expect, so I'm really perplexed... Debbie Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/#findComment-1196112 Share on other sites More sharing options...
Pikachu2000 Posted April 3, 2011 Share Posted April 3, 2011 Echo date('M') and see what you get. It probably isn't what you're expecting it to be. Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/#findComment-1196113 Share on other sites More sharing options...
doubledee Posted April 3, 2011 Author Share Posted April 3, 2011 Echo date('M') and see what you get. It probably isn't what you're expecting it to be. Ha ha. Good idea! (I was just copying this out of a book I had..) Okay, so what is the *best* way to get the YEAR and MONTH (as a number)?? Debbie Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/#findComment-1196119 Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2011 Share Posted April 3, 2011 The complete php documentation is available online or via download - http://us.php.net/docs.php The page for the date() function would be a worthwhile read. Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/#findComment-1196120 Share on other sites More sharing options...
doubledee Posted April 3, 2011 Author Share Posted April 3, 2011 The complete php documentation is available online or via download - http://us.php.net/docs.php The page for the date() function would be a worthwhile read. Okay, I got it. I needed a little "m" Thanks, Debbie Quote Link to comment https://forums.phpfreaks.com/topic/232534-date-check-not-working/#findComment-1196122 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.