Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help implementing past date validation

I need to implement something that checks if a given date is greater than today. If for example, I input a date of April 19, 2011 while today is April 15, 2011, there should be some validator/pop up error. How do I implement this?

I have my system date (today's date) working fine through php. I just don't know how to create a validation/error message when the user inputs a higher date than today.

like image 699
catsgirl008 Avatar asked Mar 06 '26 05:03

catsgirl008


1 Answers

It can be done with PHP (on server side) and with JavaScript (on client side, in browser).

Here is an example of how to do it on JavaScript:

var currentTime = new Date()
    month = currentTime.getMonth(),
    day = currentTime.getDate(),
    year = currentTime.getFullYear(),
    today = year + "-" + month + "-" + day;

var users_day = '2011-04-19';

if (users_day > today) {
     alert ("Entered day is greater than today");
}
 else {
     alert ("Today is greater than entered day");
 }
like image 69
Scherbius.com Avatar answered Mar 08 '26 19:03

Scherbius.com



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!