Compare start date and end date

Community Alums
Not applicable

I'm having problems when comparing two data/time fields in a service catalog. I have a start date that cannot be earlier than the current day/time and I have an end date field where this cannot be chosen with a date/time less than the start date or earlier.

I've tried both via scrip and via policy, but I'm stuck in this situation. Could you give me this support.

 

 

 

find_real_file.png

4 REPLIES 4

Aman Kumar S
Kilo Patron

Hey,

You follow below links to attain this.

One way is to use onChange client script to compare the two dates:
Client Side Dates in ServiceNow

Another is using onChange script client script and GlideAjax GlideAjax, to compare the fields at server side:
Client Script Date Compare

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you considered using a (Catalog) UI Policy to achieve date validations? There's almost no-code needed to achieve date validations this way. Have a look at an article I wrote on this:
No Code date validations thru (Catalog) UI Policies

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Community Alums
Not applicable

Thank you very much for the support, but I ended up using the two merged forms, I did the validation of the start date via UI policies and the validation of the end date comparing with the start date if it will be before the date/time . This way I managed to solve my problem and the tests were carried out successfully. Thank you all for your help.

ShaunSadler
Mega Expert

To compare two dates from the Catalog Client side, you might need to call GlideAjax and use a script include to do the comparison.