I want to check the current system date with booking date

Hi
ALL

I want to display the alert when user enters the time less than the system time and date should be current date and if the date is greater than current date it should ignore the alert box.
Here is the code

<script type=“text/javascript”>
function check() {
var now = new Date(),
timeParts = document.contact_form.time.value.split(‘:’),
userTime = new Date();
var year = now.getFullYear();
var month =now.getMonth()+1;
var day = now.getDate();
var today = year+“-”+month+“-”+day;
var pickdate=document.contact_form.reqdate.value

userTime.setHours(timeParts[0]);
userTime.setMinutes(timeParts[1]);
if (userTime &lt; now && pickdate == today)
{
    alert('Please enter the time greater than current time');
	}

}
</script>

Please help me out to solve the problem

Thanks
md.Samiuddin

That seems to work under certain circumstances.

What seems to be the problem, your date handling?

You can use the entered date to create the user date, then update the hour and minute sections. That way you can use the toDateString method to retrieve the date portion from the Date object, for easy comparison.


var now = new Date();

var timeParts = document.contact_form.time.value.split(':');
var userDateTime = new Date(document.contact_form.reqdate.value);
userDateTime.setHours(timeParts[0]);
userDateTime.setMinutes(timeParts[1]);

var isTodaysDate = userDateTime.toDateString() === now.toDateString();
if (isTodaysDate && userDateTime < now) {
    ...
}