Friends, we have written in the foreground program, is to collect some basic information about users, such as Start time and end time, sometimes in order to improve the effectiveness of the data, the general situation will be used to select the date control to fill out, but Ah, the program is not to solve the human error, If you deliberately choose the start date more than the end date, what do you say? So you have to use JS to do a date comparison operation ... Examples are as follows:
My page now uses a control for the user to select the date, the format of the selected value is: 2009-10-20 14:38:40
A start date, an end date, how to determine the start date can not be greater than the end date?
I didn't say it. Is there two ways of doing it?
First: Convert to date object for comparison operations
<script>
var st= "2009-10-20 14:38:40"
var et= "2009-10-20 15:38:40"
var stdt=new Date (St.replace ("-", "/"));
var etdt=new Date (Et.replace ("-", "/"));
if (STDT>ETDT) alert ("Start time must be less than end time")
</script>
The second: Direct comparison of the size can be
<script>
var st= "2009-10-20 14:38:40"
var et= "2009-10-20 15:38:40"
if (st>et) alert ("Start time must be less than end time")
</script>