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
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

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.