GlideDateTime

BoyaGaneshkumar
Tera Contributor

<p> Can anyone please give Brief about GlideDateTime () and GlideDate()  API's. with some Real time Examples.

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@BoyaGaneshkumar 

 

GlideDateTime

The GlideDateTime API handles date and time values. It's more precise than GlideDate because it includes the time component.

 

Example:

var now = new GlideDateTime(); // Creates a GlideDateTime object with the current date and time.
gs.info('Current Date and Time: ' + now.getDisplayValue()); // Outputs the current date and time in the user's preferred format.
gs.info('Current Date and Time in UTC: ' + now.getUTCDatetime()); // Outputs the current date and time in UTC format.

 

GlideDate:

The GlideDate API specifically deals with dates without the time component. It's simpler than GlideDateTime if you only need the date.

 

Example:

var date1 = new GlideDate('2024-03-15');
var date2 = new GlideDate('2024-03-20');

if (date1.before(date2)) {
    gs.info('date1 is before date2');
} else if (date1.after(date2)) {
    gs.info('date1 is after date2');
} else {
    gs.info('date1 and date2 are the same');
}

dgarad
Giga Sage

Hi @BoyaGaneshkumar 

Refer the below link.

https://www.servicenow.com/community/itsm-forum/understanding-glidedate-and-glidedatetime-in-service...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Ankur Bawiskar
Tera Patron
Tera Patron

@BoyaGaneshkumar 

you can easily find answer to this in docs and blogs etc.

Did you check that before posting question here?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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