Jump to content

Recommended Posts

I have just written a Date Verification function for my form.

The date entered by the user in the for is the date on which they Bought a certain product.

 

Now The problems I'm having are the following:

 

1) I am using Language files, and I am unsure if I can use those globals withing a function.

2) What would be the best way for me to get specific error messages to the user.

3) Is there an easier way to do this, because it all seems a bit... farfetched.

 

Here is the code to my function:

(I also should mention that "ddMonth" is a global Array retrieved from the language file.)

 

function checkDate ($day, $month, $year){

  // Februari
  if ($month == $ddMonth[1]){
  
    if ($day > 29){

	  return false;

	} elseif ($day == 29){
	  
	  // Check if the entered year is a leapyear
	  if ($year % 100 != 0 && ($year % 400 == 0 || $year % 4 == 0)){

	    return true;

	  } else {

		return false;
	  }
	  
	} else {

		return true;

	}
  	
  }
  
  // April
  if ($month == $ddMonth[3]){
  
    if ($day > 30){
      
      return false;
      
    } else {
      
      return true;
  
  }
  
  // June
  if ($month == $ddMonth[5]){
  
    if ($day > 30){
      
      return false;
      
    } else {
      
      return true;
  
  }
  
  // September
  if ($month == $ddMonth[8]){
  
    if ($day > 30){
      
      return false;
      
    } else {
      
      return true;
  
  }
  
  // November
  if ($month == $ddMonth[10]){
  
    if ($day > 30){
      
      return false;
      
    } else {
      
      return true;
  
    }

      }

}

 

Any help would be appreciated, thanks :)

Link to comment
https://forums.phpfreaks.com/topic/55623-my-date-check-function-help/
Share on other sites

Sorry about that, ddMonth is a Global array storing all of the values of months there are in various languages.

 

ddMonth is actually the "dropdown" menu used in the form so ddMonth contains

 

Januari

Februari

March

...

December

 

but the problem is in another language it's

 

Januari

Februari

MAART (dutch)

...

December

 

 

Thus If I wasn't using this dropdown array, the values wouldn't always work out.

 

And what I'm trying to archieve is wheter the date entered is a VALID date.

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.