This topic is locked
[SOLVED]

 Date Validation with 2 conditions including null date.

5/18/2010 1:14:55 PM
PHPRunner General questions
J
jackieh author

Hi Sergey,
This question is related to the Topic from 5/3/10: 'custom calendar validation and another question'**

Your response below works great but I have to check more conditions. Can you please help again?
I'm having trouble checking for a null date plus another date condition. The field being validated is nullible but if the user enters a date, it must meet these conditions:

  1. If the date value is not null AND is past one year from now, Don't Add Record
  2. If the date value is null OR is between now and one year from now, Add Record
    BTW - the field in the database that contains the date value is a varchar(10) field.
    ----------------------------------

    Sergey's response from 5/4/10
    While we don't have an option to limit date range in datepicker you can validate dates in events like BeforeAdd and BeforeEdit.
    Current date - Now()

    One year from now - DateAdd("yyyy",1,Now())
    if CDate(values("DateField)) > DateAdd("yyyy",1,Now()) then

    BeforeAdd = false

    else

    BeforeAdd = true

    end if

A
ann 5/19/2010

Hi,
use BeforeAdd/BeforeEdit events on the Events tab to check date conditions.

Here is a sample:

if (((strtotime($values["DateField"])-strtotime(now()))/31536000<1)||(!$values["DateField"]))

{ return true;}

else

{ return false;}
J
jackieh author 5/19/2010

Hi Ann,
Thanks for your reply. I'm also wondering about checking for more than one condition in an if statement, specifically I these are the checks I need to make before a record is added. Also having trouble checking for a null.

  • If the date value is not null AND is past one year from now, Don't Add Record
  • If the date value is null OR is between now and one year from now, Add Record
    Best to you and thanks again!

A
ann 5/20/2010

Hi,
try this code:

if (((strtotime(now())-strtotime($values["DateField"]))/31536000<1)||(!$values["DateField"]))

{return true;}

elseif (((strtotime(now())-strtotime($values["DateField"]))/31536000>1)&&($values["DateField"]))

{return false;}
J
jackieh author 5/20/2010

Really appreciate all your help. Thanks!