Check if user selected Time has expired

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:

  1. var targetTime = new Date().setMinutes(-5).valueOf();
  2. var today = new Date();
  3. var dd = today.getDate(); var mm = today.getMonth() + 1; //January is 0!
  4. var yyyy = today.getFullYear();
  5.  if (dd < 10) {
  6.  dd = '0' + dd }
  7. if (mm < 10)
  8. { mm = '0' + mm
  9. }
  10. today = mm + '/' + dd + '/' + yyyy;
  11. alert(today);
  12. if (jQuery('#startDatepicker').find("input").val() == today)
  13. {
  14. alert("Yes");
  15. var currentTime = jQuery('#startTimepicker').find("input").val();
  16. alert(currentTime);
  17. alert(targetTime);
  18. if (currentTime <= targetTime)
  19. {
  20. //Time Expired
  21. alert("HI");
  22.  }
  23. }
  24. 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?

  25. Thanks