Check if user selected Time has expired
Hi,
I want to check if date is today, then user should not be able to pick expired time. However, if the date selected is tomorrow, then any time can be selected.
I am trying to do a check in jquery, but not sure how to check. The date is in the format of "MM/DD/YYYY", and the time is in format of "hh:mm a". Expired time of 5 minutes is allowed
Below is the code which I have tried:
- var targetTime = new Date().setMinutes(-5).valueOf();
- var today = new Date();
- var dd = today.getDate(); var mm = today.getMonth() + 1; //January is 0!
- var yyyy = today.getFullYear();
- if (dd < 10) {
- dd = '0' + dd }
- if (mm < 10)
- { mm = '0' + mm
- }
- today = mm + '/' + dd + '/' + yyyy;
- alert(today);
- if (jQuery('#startDatepicker').find("input").val() == today)
- {
- alert("Yes");
- var currentTime = jQuery('#startTimepicker').find("input").val();
- alert(currentTime);
- alert(targetTime);
- if (currentTime <= targetTime)
- {
- //Time Expired
- alert("HI");
- }
- }
startDatepicker has the value as : 02/06/2017
startTimepicker, currentTime has the value as : 05:17 am
targetTime has the value as: 1486374940591
How to check if time has expired?
Thanks