Task 1 – ITSM : Check if the current time is greater than start date time and smaller than end date

YashwanthV18760
Tera Expert

Requirement: Check if the current time is greater than start date time and smaller than end date time. We assume here start date time and end date time are two Date/Time fields in a form. 

 

Solution: 

 

 

1. Create Fields (if not already present)

On your table:

  • start_date_time → Type: Date/Time

  • end_date_time → Type: Date/Time

  • timecheck → Type: True/False

 

2. Create Before Business Rule

Navigation:
System Definition → Business Rules → New

Set:

  • When: Before

  • Insert:

  • Update:

Screenshot 2026-02-24 115251.png

 

3. Script

Paste this in Advanced → Script

 

 
(function executeRule(current, previous /*null when async*/) {

var now = new GlideDateTime();
var start = new GlideDateTime(current.start_date_time);
var end = new GlideDateTime(current.end_date_time);

if (now.getNumericValue() > start.getNumericValue() &&
now.getNumericValue() < end.getNumericValue()) {

current.timecheck = true;
} else {
current.timecheck = false;
}

})(current, previous);
 

 

4. How It Works

  • GlideDateTime() gets current system time.

  • getNumericValue() converts dates into milliseconds for accurate comparison.

  • Logic:

     
    start < now < end → true
    otherwise → false
     
  • Because it's Before BR, value is set before record saves.

Screenshot 2026-02-24 115950.png

1 REPLY 1

Ankur Bawiskar
Tera Patron

@YashwanthV18760 

so what's the question?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader