Validate date - User should select only next month data from today's date
Hi,
I have a date field to which, I want the user to select only dates from next month from today's date. The date field is in MM/DD/YYYY format.
I tried the below code, but it is not working
- var validflag = true;
var msg = "Please provide a valid details for the below: ";
var isMessaged = false;
var inputStartDate ="";
var dtStartDate = $("input[title='My Start Date']").val();
- var todaysDate = new Date();
- var newtodaysDate = todaysDate.setMonth(todaysDate.getMonth() + 1);
- if(dtStartDate.length > 0) {
- inputStartDate = new Date(dtStartDate);
- var newinputStartDate = new Date(dtStartDate.setMonth(dtStartDate.getMonth() + 2));
- // call setHours to take the time out of the comparison
- if( (inputStartDate.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0)) || (inputStartDate < todaysDate ) || (newtodaysDate > newinputStartDate.getTime() ) )
- {
- // StartDate equals today's date or Date is in the Past
- msg = msg + "<br/> Start Date should be greater than Today's Date and should have 1 month gap";
- isMessaged = true;
- validflag = false;
- }
- }
-
I am getting the error as "Object doesn't support property or method 'getMonth' "
How to fix this?
- Thanks