Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to check if the date is in the future or within 30 days(past)?

Naveen Kumar
Tera Contributor

I need to check that the Hire Date is in the future or within 30 days (prior or past).

Writing a BR to check and set a configuration item to onboarding.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

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

	// Add your code here
	var nowTime = new GlideDateTime();
	nowTime.addDaysUTC(30);

	var nowTime1 = new GlideDateTime();
	nowTime1.addDaysUTC(-30);

	var currentTime = new GlideDateTime();

	var newHireDate = new GlideDateTime(current.u_date); // give the date field name here


	if(newHireDate.getNumericValue() > currentTime.getNumericValue() || (newHireDate.getNumericValue() > nowTime1.getNumericValue() || newHireDate.getNumericValue() < nowTime.getNumericValue())){
		// this means Hire Date is in the future or within 30 days (prior or past).

		// use your logic here

	}

})(current, previous);

Regards
Ankur

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

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

	// Add your code here
	var nowTime = new GlideDateTime();
	nowTime.addDaysUTC(30);

	var nowTime1 = new GlideDateTime();
	nowTime1.addDaysUTC(-30);

	var currentTime = new GlideDateTime();

	var newHireDate = new GlideDateTime(current.u_date); // give the date field name here


	if(newHireDate.getNumericValue() > currentTime.getNumericValue() || (newHireDate.getNumericValue() > nowTime1.getNumericValue() || newHireDate.getNumericValue() < nowTime.getNumericValue())){
		// this means Hire Date is in the future or within 30 days (prior or past).

		// use your logic here

	}

})(current, previous);

Regards
Ankur

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