Jump to content

Date Check not working


doubledee

Recommended Posts

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?!  :shrug:

 

 

 

Debbie

 

 

Link to comment
https://forums.phpfreaks.com/topic/232534-date-check-not-working/
Share on other sites

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.