Problem with date validation

kouros91

Member
Hi
I have a date element DATEVERS and i have a php condition for validation.
I have another element date in another table named VARDATE.
I would like that Validation for DATEVERS is good for DATEVERS>VARDATE
I'm written this code but it doesn't work :

Code:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$my_userid = '{$my->id}';
$query
    ->select('VARDATE')
    ->from('g363_users')
    ->where('id = ' . $db->quote($my_userid));

$db->setQuery($query);
$fieldA = $db->loadResult();
$thedate = strtotime($fieldA);

$date = JFactory::getDate($data);
    $date = $date->toUnix();
    //$midnight = JFactory::getDate(strtotime('today'));
    $thedate = $thedate->toUnix();
    if ($date < $thedate){
        return true;
    }else{
        return false;
    }

My element VARDATE from g363_users can be accessed with a list names utilisateurs
it's {utilisateurs___VARDATE} (when id = user id)

Thank you for help
Nicolas
 
Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
    ->select('VARDATE')
    ->from('g363_users')
    ->where('id = ' . $myDb->quote('{$my->id}'));
$myDb->setQuery($myQuery);
$fieldA = $myDb->loadResult();
$thedate = new DateTime($fieldA);
$date = new DateTime($data);
return $date < $thedate;

Note that you might need to add some exception handling if either of those values might not be valid dates.

-- hugh
 
Oh, and you said ...

i have a php condition for validation.

Just to be clear, in the PHP validation, there are two boxes for code. One is "Condition", which determines whether the validation should be run. And "PHP Code", which is the actual validation code. You need to use the second one.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top