Professional Documents
Culture Documents
Beginner's Guide - GlideDate and GlideDateTime
Beginner's Guide - GlideDate and GlideDateTime
Beginner's Guide - GlideDate and GlideDateTime
ServiceNow:
ServiceNow developers frequently work with date and time data to manage records and
processes effectively. GlideDate() and GlideDateTime() are essential classes in ServiceNow for
handling date and time operations programmatically. This article provides a detailed overview of
these classes, their methods, practical examples, and the importance of initialization.
GlideDateTime(): GlideDateTime extends GlideDate to include both date and time components.
It offers additional functionalities such as time zone management, date-time arithmetic, and
formatting date-time strings.
GlideDate Methods:
Example:
Example:
Examples:
GlideDateTime Methods:
• getDayOfWeek(): Returns the day of the week as an integer (1-7).
Example:
Examples:
Example:
var gdt = new GlideDateTime();
var dayOfMonth = gdt.getDayOfMonth();
gs.info('Day of Month: ' + dayOfMonth); // Outputs: Day of Month: 21
Example:
Example:
// Convert to GlideDateTime
var gdtFromExcel = new GlideDateTime();
gdtFromExcel.setValue(formattedExcelDateValue);
gs.info('GlideDateTime from Excel: ' + gdtFromExcel.getDisplayValue());
Conclusion
Mastering GlideDate and GlideDateTime is essential for efficiently managing date and time data
in ServiceNow applications. By understanding these classes and their methods, developers can
perform accurate date operations, handle time zone conversions, and format date-time strings
according to user preferences.
https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-
namespace/c_GlideDateScopedAPI#r_ScopedGlideDateGetByFormat_String