Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 507
Pratik Bhatt Avatar asked Jan 29 '13 11:01

Pratik Bhatt


People also ask

How do you check if a date is greater than 30 days in Javascript?

getTime() + thirtyDaysInMs; if (date > timestampThirtyDaysInFuture) { console. log('date is more than 30 days into the future'); return true; } else { console. log('date is NOT more than 30 days into the future'); return false; } } // 👇️ true console.

How do you compare two dates in the same day?

To check if two dates are the same day, call the toDateString() method on both Date() objects and compare the results. If the output from calling the method is the same, the dates are the same day.


1 Answers

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.
}
like image 74
Cerbrus Avatar answered Oct 04 '22 19:10

Cerbrus