comparing two dates in javascript
-
i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);
-
i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);
-
i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);
You seem to have forgotten to ask a question. You've told us what you want to do; you've shown us the code you've got; but you haven't told us what the problem is. If you're getting an error, post the full details of the error, and tell us which line of code it's thrown from. If it's not doing what you want, tell us what the inputs are, and describe what it's actually doing.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
i want to compare dates . startjourney=moment(moment($('#onDate').val()).format("DD/MM/YYYY")+' '+ $('#starttime').val(),"DD/MM/YYYY h:mm A");//concate date and time am getting 27/01/2016 12:00 AM newDate=moment(startjourney).add(mapDuration[0],'days').add(mapDuration[2],'hours').add(mapDuration[4],'minutes').format("DD/MM/YYYY hh:mm A");//29/01/2016 10:17 AM // returnJourneyDate=newDate.split(" ")[0]; // // endTime=moment(newDate.split(" ")[1]+ ' '+newDate.split(" ")[2],"h:mm A "); // selectedTime=moment($('#starttime').val(),"h:mm A"); alert(moment($('#returntime').val(),"HH:MM").toDate()); selectedjourney=moment($('#returndate').val()+' '+ moment($('#returntime').val(),"HH:MM")).toDate();//concate date and time as strings selectedDate=moment(selectedjourney,"DD/MM/YYYY h:mm A").toDate(); var date=new Date(selectedjourney,"DD/MM/YYYY hh:mm tt"); var d=moment( $('#returntime').val(),"HH:MM").toDate(); var h=new Date(selectedDate); if(selectedjourney.isBefore(newDate))// test selected one is before newDate bootbox.alert( "Return journey time must be after " + newDate);
Is this what you want?? [Demo] Date Comparision in JavaScript - JSFiddle[^]