How to find the dates are in between holidays date

Anthony78
Kilo Sage

We have holiday schedules and trying to book the appointment from Catalog item. I would like to display message if user is selecting start or end date between or on the holiday dates.

 

When i try to get the date values and I'm getting it in below format 

13-Aug-2024 04:15 PM

 Below is the script i tried but not going inside IF statement

 

   getStartDate: function() {
        var getStart = this.getParameter('sysparm_startDate'); // Booking Start date
        var StartGR = new GlideRecord('cmn_schedule_span');
        StartGR.addQuery('schedule', 'c634e328db267510877bb6e4e29619b2');
        StartGR.query();
        while (StartGR.next()) {
            var result = false;
            if (getStart > StartGR.start_date_time.getDisplayValue() && StartGR.end_date_time.getDisplayValue() < getStart) {
                result = true;

            } else {
                result = false;
            }

            return result; // return false or true ;
        }
3 REPLIES 3

Alp Utku
Mega Sage

If the holiday schedules are known, you could use one of the below date validations without coding

 

https://www.servicenow.com/community/developer-articles/no-code-date-validations-through-catalog-ui-...

@Alp Utku 

 

We have a holiday schedules in different table and I have to validate those dates with current variables .

Above article is using OOB filters like today or between.

Slava Savitsky
Giga Sage

Never compare display values of date/time fields. There are lots of possible formats and you never know what the result of ">" and "<" comparisons is going to be because they are compared as strings. Moreover, different users can have different date/time format settings.

 

Instead, you should always compare numeric representations of date/time field values.