i want to check var check_val in between two time var open_time and var close_time
var open_time = "23:30";
var close_time = "06:30";
var check_val ="02:30";
if(Date.parse ( check_val ) > Date.parse ( open_time ) && Date.parse ( check_val ) < Date.parse ( close_time )){
var flag=1;
} else {
var flag=2
}
the result is always else part
You could create your own object to hold time and then write a function which uses it:
Date.parse()
accepts dates in RFC2822 or ISO8601 formats.In your case, it always returns
NaN
.Using the appropriate Date format works as expected:
If you are just comparing times and not dates you could just do a string comparison