Compare time value

I am trying to compare a time value in JS but not sure how to do it. I need to compare a time value of 15:30 and if that tie value is exceeded then do something in an if statement.

I have included the limited code I have and would be grateful if someone could offer me some assistance.

Many thanks

    var time = new Date();
    var display = (time.getHours() + ":" + time.getMinutes());
    //console.log(display);
    if (time.getHours() + time.getMinutes() >= 15:30) {
      if (records == '0') {
           
           $("#dept").prop("disabled", true).attr('data-placeholder', 'No data to display').val('').trigger("chosen:updated");
           $('#rtrvmessage').html('There are no boxes in that department to destroy.').css({  
           'margin-left': '7px',
           'margin-top': '8px',
           color: 'red'
           });
           
           return false;
        }
 var time = new Date();
 var threethirty = (new Date()).setHours(13,30,0,0);
if(time > threethirty) {

EDIT: to be pedantic, add seconds and milliseconds.

NOTE: This (like all Javascript based time metrics) is based on the user’s current timezone. If you want a fixed time point, use the UTC components of the date object to determine it.

Thank you very much. I shall try this and post back.

Excellent. Thank you sir. Always appreciate your help.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.