Check if specific date is in between two dates?

Evren Yamin
Tera Contributor

Hello,

I have a script in business rule that gets the value of recipients of an email. There are emails that has many recipients.
I want to check if the recipients start date is in between the created and updated date of my custom table. And if not then they should not be included in my output.
All dates are in date/time type.
Is there a way to do this?

Thank you.

Appreciate all the help.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Evren Yamin 

Something like this

var createdDate = new GlideDateTime(<createdTime>);

var updatedTime = new GlideDateTime(<updatedTime>);

var startDate = new GlideDateTime(<startDate>);

if(startDate.getNumericValue() < updatedTime.getNumericValue() && startDate.getNumericValue() > createdDate.getNumericValue()){

// within

}

else{

// outside date

}

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Hi Evren,

you can use this :

https://developer.servicenow.com/dev.do#!/reference/api/paris/server_legacy/c_GlideDateTimeAPI#r_GDT-compareTo_O

 P.S. I assume you have to use 3 dates - the initial occurence date A, the allowed date B and the responce date C. So you need to add B to A = AB and then compare to C. Is that so or I am not following?

Cheers,

Joro

Hello, 

dateA - start_date
dateB - end_date
dateC - created_date
I need to check if dateC is in between dateA and dateB.
Now, that's not all. Every recipient on the list has different created date.
Let's say the outputs are:
1st recipient - dateC is between dateA and dateB
2nd recipient - dateC is not between dateA and dateB

I need to get the data of the 1st recipient only since it's the only one where the condition ended up true.

I'm sorry if my explanation is confusing. 

Ankur Bawiskar
Tera Patron
Tera Patron

@Evren Yamin 

Something like this

var createdDate = new GlideDateTime(<createdTime>);

var updatedTime = new GlideDateTime(<updatedTime>);

var startDate = new GlideDateTime(<startDate>);

if(startDate.getNumericValue() < updatedTime.getNumericValue() && startDate.getNumericValue() > createdDate.getNumericValue()){

// within

}

else{

// outside date

}

Regards
Ankur

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

@Evren Yamin 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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