Compare two date fields

Anil74
Tera Guru

Hi All,

I have a requirement that have to compare start date and end date, if start date is greater than the end date need to show alert using on change client script.

i tried with below code but not working. any one guide me on this.

var st = g_form.getValue('u_start_time');

var et = g_form.getValue('u_end_time');

if(st > et)

{

alert("Start time should be less than the end time");

}

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Anil,



If they are only of type date then following link should be helpful:


In Client Script, how can I compare 2 dates(with time) that are in different format.


Client script to validate start/end date fields


Compare 2 Dates in On Load Client script.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Please help me 

https://community.servicenow.com/community?id=community_question&sys_id=aa6f9ebb1b23d810d2ccea89bd4bcbef

Prateek kumar
Mega Sage

Hello Anil


This thread will help you


How do I ensure one date field does not start before another date field?



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Anil,



Any update on this?


Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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