Glide DateTime duration help

chaitanya2948
Tera Contributor

Hi Team,

 

I have already existing requirements when change request  plane start date time,plane end date time from 8:00 AM to 6:00 PM IST only the approver should trigger, this script correctly working

New requirement :

-when the User selects with in date & time frame need to check 

ex: if user selects start and end date & time: 12-07-2023 7:00AM to 12-07-2023 7:00 PM[This time is with in time frame of 8 am to 6:pm] I need this logic could you please help me?

 

ex: if user selects tart and end date & time: 12-07-2023 6:00AM to 12-07-2023 7:00 AM[This is not within time frame so we need to ignore]

Regards,

CK.

 

2 REPLIES 2

Prashant Ahire
Kilo Sage

@chaitanya2948 

  var startTime = new GlideDateTime();
    startTime.setDisplayValue("08:00:00");

    var endTime = new GlideDateTime();
    endTime.setDisplayValue("18:00:00");


    // Get the selected start and end date & time
    var startDateTime = new GlideDateTime(current.start_date);
    var endDateTime = new GlideDateTime(current.end_date);

    // Check if the selected time falls within the specified time frame
    if (startDateTime.compareTo(startTime) >= 0 && endDateTime.compareTo(endTime) <= 0) {
        // Time frame is valid, perform your logic here
        gs.addInfoMessage("Selected time frame is within 8:00 AM to 6:00 PM IST");   ///add Your Logic here
    } else {
        // Time frame is not valid, ignore or perform alternative logic
        gs.addInfoMessage("Selected time frame is outside the allowed time frame");
    }
 
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Prashant Ahire

No it's not working always jumps to else block, 

chaitanya2948_0-1701935210491.png

chaitanya2948_1-1701935234235.png