- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 09:42 PM
Hi SNC,
Please see this, I do not understand why this return false?
I get false for >> gs.info(today>incoming);
var today = gs.nowDateTime()
var incoming = '28-08-2022 12:00 AM';
gs.info(today);
gs.info(incoming);
gs.info(today>incoming);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 01:51 AM
This below code works >>
use getValue() method instead of getDisplayValue()
Reference : Community_Page
var today = gs.nowDateTime();
var incoming = '28-08-2022 12:00 AM';
var gdt_incoming = new GlideDateTime();
gdt_incoming.setDisplayValue(incoming, "dd-MM-yyy hh:mm a");
var gdt_incoming_converted = gdt_incoming.getValue();
gs.info('gdt_incoming_converted : ' + gdt_incoming_converted);
var gdt_today = new GlideDateTime();
gdt_today.setDisplayValue(today, "dd-MM-yyy hh:mm a");
var gdt_today_converted = gdt_today.getValue();
gs.info('gdt_today_converted : ' + gdt_today_converted)
gs.info(gdt_today_converted > gdt_incoming_converted);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 01:10 AM
Result :
*** Script: patchStartGDT : 25-09-2022 08:13 PM
*** Script: todaygdt : 02-09-2022 06:09 PM
*** Script: false
var dateStart = "25-09-2022 08:13 PM";
var gdtStart = new GlideDateTime();
gdtStart.setDisplayValue(dateStart, "dd-MM-yyy hh:mm a");
var patchStartGDT = gdtStart.getDisplayValue();
gs.info('patchStartGDT : ' + patchStartGDT);
var today = new GlideDateTime();
var todaygdt = today.getDisplayValue();
gs.info('todaygdt : ' + todaygdt);
gs.info(todaygdt > patchStartGDT);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 11:48 PM
Please use GlideDateTime() in the incoming variable and as already suggested by others you should be good
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 01:13 AM
Hi, try This.var today = new gs.nowDateTime();
var incoming = new GlideDateTime('28-08-2022 12:00 AM');
gs.info(today);
gs.info(incoming);
gs.info(today>incoming);
you did not add new before gs.nowDateTime(); and you should add new GlideDateTime before date and close it in brackets.
more info here:https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/c_APIRef
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 01:31 AM
Why the output of this? >> gs.info(today);
Is showing like this? >> *** Script: [object GlideSystemDateUtil2]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2022 01:51 AM
This below code works >>
use getValue() method instead of getDisplayValue()
Reference : Community_Page
var today = gs.nowDateTime();
var incoming = '28-08-2022 12:00 AM';
var gdt_incoming = new GlideDateTime();
gdt_incoming.setDisplayValue(incoming, "dd-MM-yyy hh:mm a");
var gdt_incoming_converted = gdt_incoming.getValue();
gs.info('gdt_incoming_converted : ' + gdt_incoming_converted);
var gdt_today = new GlideDateTime();
gdt_today.setDisplayValue(today, "dd-MM-yyy hh:mm a");
var gdt_today_converted = gdt_today.getValue();
gs.info('gdt_today_converted : ' + gdt_today_converted)
gs.info(gdt_today_converted > gdt_incoming_converted);