Link to home
Start Free TrialLog in
Avatar of Whedonite
WhedoniteFlag for Afghanistan

asked on

Compare 2 dates from Form with PHP

Hi,

I do not have much experience coding and am trying to compare 2 dates as part of a form validation.

Basically, user inputs a "depart" date and a "return" date to a form.  The dates need to be compared, and if the return date is earlier than the depart date it should throw an error "Return date must be later than depart date" and stop the form from being sent with wrong dates.

Any help is appreciated!!

Thanks!
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Read this while I put together an example that shows how this kind of testing is done.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Back in a moment... ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Plungjan
I strongly suggest you also add a client validation since it is not worth going to the backend if the dates are wrong. That said, you always should test on the server too...