Jump to content

My Date check function (Help)


Pastulio

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.

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.