How to check if a Date is in between of 2 other Dates?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Triggerz
    Member
    • May 2024
    • 66

    How to check if a Date is in between of 2 other Dates?

    Hi,

    I created an entity to record the bookings of conference rooms. Before saving, I wanted to check if there is already an existing record with a schedule conflict to what is being added.
    I created the formula below and placed it in the API Before Save Script formula section, but I couldn't get it the right logic to work. Not sure if there is a Between() function that can easily do this. Please help.

    Code:
    $bInsideExist = record\exists('CConfRoom', 'dateStart>=', dateStart, 'dateEnd<=', dateEnd);
    $bFrontExist = record\exists('CConfRoom', 'dateStart<=', dateStart, 'dateEnd<=', dateEnd);
    
    if($bStartExist){
    recordService\throwForbidden('The date & time of this meeting has a conflict with an existing booking. Please select a different Date & Time');
    }
    Thanks...
Working...