Pratik Bhatt Pratik Bhatt - 1 year ago 86
Javascript Question

Check Date greater than 30 days from today's date

I am using jQuery datepicker and tried to find out difference between todays date and selected date , but getting issues... rather than issues... I was not able to find it perfectly...

I tried to do this on 'onSelect event of datepicker '

Question:
How to check whether selected Date using jQuery Datepicjer is greater than 30 days from todays date ?

Any help will be appreciated....!!
note: dont want to use any libraries, I need to solve this by using only jQuery.

Answer Source

Get the timestamp for 30 days from now:

var timestamp = new Date().getTime() + (30 * 24 * 60 * 60 * 1000)
//                                      day hour  min  sec  msec

Compare that timestamp with the timestamp for the selected date.

if (timestamp > selectedTimestamp) {
    // The selected time is less than 30 days from now
}
else if (timestamp < selectedTimestamp) {
    // The selected time is more than 30 days from now
}
else {
    // -Exact- same timestamps.
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download