Due Date Field GlideDateTime comparison
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 04:40 AM
Hi All,
We have a field Due Date on catalog task form and I have to compare the old and new values on change of due date field in a onChange Client Script.
I am simply getting the value using g_form and then doing the equal to check , do I need to convert these dates or a simple comparison is fine.
Thanks in advance.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 04:44 AM
simply comparing won't work
If you want to compare 2 date/time in client script, take this as example where I am comparing the start and end dates
function onSubmit() {
//Type appropriate comment here, and begin script below
g_form.hideErrorBox('start_date');
g_form.hideErrorBox('end_date');
if(g_form.getValue('start_date') != '' && g_form.getValue('end_date')){
var start = new Date(g_form.getValue('start_date')).getTime();
var end = new Date(g_form.getValue('end_date')).getTime();
if(end < start){
var message = 'Please give valid start and end dates';
g_form.showErrorBox('start_date', message);
g_form.showErrorBox('end_date', message);
return false;
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:16 AM
Hi @Ankur Bawiskar ,
This piece of code will not work :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:20 AM
okay so you want to compare oldValue and newValue
then oldValue != newValue will work and you should be good to use that.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 05:25 AM
Just a discussion point out here @Ankur Bawiskar , I had this confusion of whether to use getTime or not that is why I created this thread however if oldValue and newValue will work in comparison will something like you posted in your piece of code for start date and end date , not work unless it is converted to milliseconds using getTime function ?
Also comparing oldValue and newValue is that a good and recommended practice?