i have startdate and enddate string and i m converting string to date object
var startdate = start_date[3]+'-'+month_value_start+'-'+start_date[2]+' '+start_time[0]+':'+start_time[1]+':00';
var enddate = end_date[3]+'-'+month_value_end+'-'+end_date[2]+' '+end_time[0]+':'+end_time[1]+':00';
var s_date = new Date(startdate);
var e_date = new Date(enddate);
startdate and enddate format is like 2014-02-20 00:00:00
i want to compare this date object if s_date is greater than e_date popup will be shown to user
if(s_date > e_date)
{
alert('Start Date Cannot Be Greater Than End Date');
}
but some how if condition is not executing even if startdatetime is greater than enddatetime.
how to solve this issue any suggestions ?
Solved
program which i m using, automatically changes enddate in runtime if startdate is greater than end date. but no update on frontend ie datetimepicker textbox so on frontend enddate remains less than startdate but in background code has modified the enddate variable and that variable i was using to compare dates....sorry for troubling u guys....and thanks for helping me.
s_dateis not larger thane_date. Make sure the date objects are created correctly.>is such a simple operation, that the only reason why the the condition would be false is that the date objects are not the ones you intend to have, ands_dateis in fact not greater thane_date. How do you know thats_dateis truly larger? Did you doconsole.log(s_date.toString(), e_date.toString())? Unless you provide a running example wheres_dateis later thane_dateands_date > e_dateisfalse, I will stick to my opinion.startdate, but nots_date. What doesalert(new Date(startdate))show you?