This topic is locked
[SOLVED]

 Validating a date field is not less than current date

9/1/2014 8:42:09 AM
PHPRunner General questions
G
g_parry author

Two days now working on this



if (toPHPTime(Now()) > toPHPTime($values["Start Date"]))

{

$message = "Start date can not be in the past.";
return false;

}

else
{



return true;

}


It doesn't seem to matter what way I write it the result is never correct.
What I am trying to do is check the start date is greater than or equal to the current date, I don't mind how this is done, first I tried to set the add page so that the user could not pick a day before the current date but I failed to find a way to do that.
The code above I putting in the before record added event

Admin 9/1/2014

Check this article for inspiration:

http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php
It explains how to calculate difference between two dates in PHP.

G
g_parry author 9/4/2014



Check this article for inspiration:

http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php
It explains how to calculate difference between two dates in PHP.


Thanks Sergey but maybe there was too much on that link for my small brain to comprehend. I kept getting close except I was getting the "date cannot be in the past" message on the current date.
Finally I did get it to work with the following:



if (strtotime($values["Start Date"]) < (Time()-86400))


This seems to work correctly but I'm open to other suggestions if it can be done in a more accurate way

Admin 9/4/2014

If it works you probably don't need to worry about it. Your code makes sense now.