Click here to Skip to main content
16,011,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i dont want my start date to be greater than end date..how can i do this using jquery?

What I have tried:

Can i get the value using parseInt function?
Posted
Updated 18-May-17 17:32pm
Comments
F-ES Sitecore 18-May-17 5:38am    
Google "compare dates jquery" and you'll find lots of examples.

for example, if you are using MM/dd/yyyy format
To compare two dates,First you will have to convert the date string in to a Javascript Date object

function getDateObj(dateString) {
    var parts = dateString.split('/');
    var month = parts[0];
    var date = parts[1];
    var year = parts[2];
    return new Date(year, month, date);
}

var date1 = document.getElementById('txtStartDate').value;
var date2 = document.getElementById('txtEndDate').value;
var dateObjFrom = getDateObj(date1)
var dateObjTo = getDateObj(date1)
if (dateObjFrom > dateObjTo) {
    alert('Date From is greater')
}
 
Share this answer
 
v2
// assume textboxes as startdate & enddate
var startDt=document.getElementById("startdate").value;
var endDt=document.getElementById("enddate").value;
//on change of the start date, compare with end date

if( (new Date(startDt).getTime() < new Date(endDt).getTime()))
{
//do your code
}
else
// alert them to select start date lesser than end date
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900