I need to show an array of values based on current date, for example show only 10am to 13am if we are on current date, if not show all...this is what i have done so far but i cant get it working again after i select the same day as today..

            var getDatePickerValue = $('[name="datepicker"]').val();
            var tdate = new Date();
            var dd = tdate.getDate(); //yields day
            var month = tdate.getMonth()+1;
            var yyyy = tdate.getFullYear(); //yields year
            var currentDate= dd + "/" +((month < 10 ? '0' +  month : month)) + "/" + yyyy;

            var newOptions = [];
            this.options.each(function (obj) {
                    value: obj.value,
                    label: obj.label,
                    disabled: obj.disabled,

            if (getDatePickerValue == currentDate) {
                newOptions.shift(); //here i remove the first value, i guess 10mam

            } else {
               //if we are not on same day i need to show again all obj from the each statment
  • Check your getDatePickerValue and currentDate format are the same or not? if not then your condition will not true and it's not worked. – Mital Shah May 28 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.