- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:22 AM
Hi all,
Can anyone tell me why the dates are unequal and how can I convert this dateTime into time so that the both dates will be equal.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:31 AM
@Prathamesh Cha1 Update your script as follows.
var val = '';
var date = new GlideRecord('question_answer');
date.addQuery('sys_id', '725fb14c1b9a31d01eeafc07cb4bcb42')
date.query();
if(date.next()){
val = date.value;
gs.print('expected date')
gs.print(val)
var gdt = new GlideDateTime(val);
gdt.getDate();
gdt.addDays(-14);
gs.print('final expected date')
gs.print(gdt)
var td = new GlideDate();
gs.print('today date')
gs.print(td)
if(gdt.getDate().getDisplayValue()==td.getDisplayValue()){
gs.print('equal')
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:27 AM
Hello @Prathamesh Cha1
You are comparing todays date with the date which is 14 days prior, so it will come up as unequal only.
secondly for extract time from your gdt variable.
add this line of code.
var arr = gdt.split(" ");
gs.info(arr[1]);
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:31 AM
@Prathamesh Cha1 Update your script as follows.
var val = '';
var date = new GlideRecord('question_answer');
date.addQuery('sys_id', '725fb14c1b9a31d01eeafc07cb4bcb42')
date.query();
if(date.next()){
val = date.value;
gs.print('expected date')
gs.print(val)
var gdt = new GlideDateTime(val);
gdt.getDate();
gdt.addDays(-14);
gs.print('final expected date')
gs.print(gdt)
var td = new GlideDate();
gs.print('today date')
gs.print(td)
if(gdt.getDate().getDisplayValue()==td.getDisplayValue()){
gs.print('equal')
}
}
Hope this helps.