This topic is locked
[SOLVED]

 Validate a input date

8/28/2013 10:33:01 AM
PHPRunner General questions
L
lijn76 author



[color="#494949"]
[color="#494949"][font="Tahoma, Helvetica,"]

$value1 = strtotime("+10 days");[/font][/color]
[color="#494949"]
[color="#494949"][font="Tahoma, Helvetica,"]{
}

[color="#494949"]
[color="#494949"]
BEGIN

DECLARE dummy INT;

IF (NEW.jokerdatum < CURDATE() + INTERVAL 10 DAY OR NEW.jokerdatum > CURDATE() + INTERVAL 365 DAY)

THEN

SELECT 'Any Message' INTO dummy FROM ONGEOORLOOFDE_JOKERDATUM WHERE used = 'anything';

END IF;

END
That works fine, but the error message don't look nice.
anyone?[/font]

C
cgphp 8/28/2013
$value1 = strtotime("+10 days");

$value2 = strtotime("+365 days");

$Jokerdatum = strtotime($values["Jokerdatum"]);

if($Jokerdatum >= $value1 && $Jokerdatum <= $value2)

{

return true;

}

$message = 'Date not valid';

return false;
L
lijn76 author 8/30/2013


$value1 = strtotime("+10 days");

$value2 = strtotime("+365 days");

$Jokerdatum = strtotime($values["Jokerdatum"]);

if($Jokerdatum >= $value1 && $Jokerdatum <= $value2)

{

return true;

}

$message = 'Date not valid';

return false;



Thanks for your answer.

I struckled with some variations on this and always get the same outcome.
The result is both times the error message. 'Date not valid';

In case of giving a valid date aswell as giving a invalid date.

So when the date is valid, it is not saved as it should.
I putted this in a Before record added event on the ADD page

I am using phpr 6.2

C
cgphp 8/30/2013

What is the entered date and in which format?
The strtotime guide says:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

L
lijn76 author 8/31/2013

I have changed it to:
$value1 = date(mm-dd-YYYY) + 10 ; (if [size="2"]date(YYYY-mm-dd) or [/size][size="2"]date(dd-mm-YYYY) it make no difference[/size]

$value2 = date(mm-dd-YYYY) +365 ; (this to make no difference)

$Jokerdatum = $values ["jokerdatum"];
if ($Jokerdatum >= $value1 [size="3"]&&[/size] $Jokerdatum <= $value2)
//( If I change this in: [size="2"]if ($Jokerdatum >= $value1 [/size][size="3"]OR[/size][size="2"] $Jokerdatum <= $value2 ) It saves both times, valid and invalid date and I understand that. So it can be saved [/size]

[size="2"]//why not with && or AND instead?[/size]
[size="2"]{[/size]

return true;

}

$message = 'Date not valid';

return false;