GlideDateTime - Global

The GlideDateTime class provides methods for performing operations on GlideDateTime objects, such as instantiating GlideDateTime objects or working with glide_date_time fields.

Use the GlideDateTime methods to perform date-time operations, such as instantiating a GlideDateTime object, performing date-time calculations, formatting a date-time, or converting between date-time formats.

GlideDateTime - add(GlideTime time)

Adds a GlideTime object to the current GlideDateTime object.

Table 1. Parameters
Name Type Description
time GlideTime The time to add.
Table 2. Returns
Type Description
void

Scoped equivalent

To use the add() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - add(GlideTime gd).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
var gtime1 = new GlideTime();
gtime1.setValue("00:00:20");
gdt.add(gtime1);
gs.print(gdt.getTime());

Output: 1970-01-01 08:00:20

GlideDateTime - add(Number milliseconds)

Adds a specified number of milliseconds to the GlideDateTime object.

Table 3. Parameters
Name Type Description
milliseconds Number The number of milliseconds to add
Table 4. Returns
Type Description
void

Scoped equivalent

To use the add() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - add(Number milliseconds).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getNumericValue());
gdt.add(10);
gs.print(gdt.getNumericValue());
Output:
1314777600000
1314777600010

GlideDateTime - addDays(Number days)

Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.

Use addDaysLocalTime() and addDaysUTC() instead of this method.

Table 5. Parameters
Name Type Description
days Number The number of days to add. Use a negative number to subtract.
Table 6. Returns
Type Description
void

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addDays(-1);
gs.print(gdt.getDate());

Output: 2011-08-30

GlideDateTime - addDaysLocalTime(Number days)

Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.

The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts days using the local date and time values.

Table 7. Parameters
Name Type Description
days Number The number of days to add. Use a negative value to subtract.
Table 8. Returns
Type Description
void

Scoped equivalent

To use the addDaysLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addDaysLocalTime(Number days).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addDaysLocalTime(-1);
gs.print(gdt.getLocalDate());

Output: 2011-08-30

GlideDateTime - addDaysUTC(Number days)

Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.

The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts days using the UTC date and time values.

Table 9. Parameters
Name Type Description
days Number The number of days to add. Use a negative value to subtract.
Table 10. Returns
Type Description
void

Scoped equivalent

To use the addDaysUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addDaysUTC(Number days).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addDaysUTC(-1);
gs.print(gdt.getDate());

Output: 2011-08-30

GlideDateTime - addMonths(Number months)

Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.

Use addMonthsLocalTime() or addMonthsUTC() instead of this method.

Table 11. Parameters
Name Type Description
months Number The number of months to add. Use a negative number to subtract.
Table 12. Returns
Type Description
void

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addMonths(2);
gs.print(gdt.getDate());

Output: 2011-10-31

GlideDateTime - addMonthsLocalTime(Number months)

Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.

The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts months using the local date and time values.

Table 13. Parameters
Name Type Description
months Number The number of months to add. Use a negative value to subtract.
Table 14. Returns
Type Description
void

Scoped equivalent

To use the addMonthsLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addMonthsLocalTime(Number months).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addMonthsLocalTime(2);
gs.print(gdt.getDate());

Output: 2011-10-31

GlideDateTime - addMonthsUTC(Number months)

Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.

The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts months using the UTC date and time values.

Table 15. Parameters
Name Type Description
months Number The number of months to add. Use a negative number to subtract.
Table 16. Returns
Type Description
void

Scoped equivalent

To use the addMonthsUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addMonthsUTC(Number months).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addMonthsUTC(2);
gs.print(gdt.getDate());

Output: 2011-10-31

GlideDateTime - addSeconds(Number seconds)

Adds a specified number of seconds to the GlideDateTime object.

Table 17. Parameters
Name Type Description
seconds Number The number of seconds to add
Table 18. Returns
Type Description
void

Scoped equivalent

To use the addSeconds() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addSeconds(Number seconds).

var gdt = new GlideDateTime("2011-12-07 08:00:00");
gdt.addSeconds(1000);
gs.print(gdt.getValue());

Output: 2011-12-07 08:16:40

GlideDateTime - addWeeks(Number weeks)

Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.

Use addWeeksLocalTime() and addWeeksUTC() instead of this method.

Table 19. Parameters
Name Type Description
weeks Number The number of weeks to add. Use a negative number to subtract.
Table 20. Returns
Type Description
void

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addWeeks(-1);
gs.print(gdt.getDate());

Output: 2011-08-24

GlideDateTime - addWeeksLocalTime(Number weeks)

Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.

The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts weeks using the local date and time values.

Table 21. Parameters
Name Type Description
weeks Number The number of weeks to add. Use a negative number to subtract.
Table 22. Returns
Type Description
void

Scoped equivalent

To use the addWeeksLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addWeeksLocalTime(Number weeks).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addWeeksLocalTime(-1);
gs.print(gdt.getDate());

Output: 2011-08-24

GlideDateTime - addWeeksUTC(Number weeks)

Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.

The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts weeks using the UTC date and time values.

Table 23. Parameters
Name Type Description
weeks Number The number of weeks to add. Use a negative number to subtract.
Table 24. Returns
Type Description
void

Scoped equivalent

To use the addWeeksUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addWeeksUTC(Number weeks).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gdt.addWeeksUTC(-1);
gs.print(gdt.getDate());

Output: 2011-08-24

GlideDateTime - addYears(Number years)

Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.

Use addYearsLocalTime() or addYearsUTC() instead of this method.

Table 25. Parameters
Name Type Description
years Number The number of years to add. Use a negative value to subtract.
Table 26. Returns
Type Description
void

var gdt = new GlideDateTime("2010-08-31 08:00:00");
gdt.addYears(1);
gs.print(gdt.getDate());

Output: 2011-08-31

GlideDateTime - addYearsLocalTime(Number years)

Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.

The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts years using the local date and time values.

Table 27. Parameters
Name Type Description
years Number The number of years to add. To subtract use a negative value.
Table 28. Returns
Type Description
void

Scoped equivalent

To use the AddYearsLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addYearsLocalTime(Number years).

var gdt = new GlideDateTime("2010-08-31 08:00:00");
gdt.addYearsLocalTime(1);
gs.print(gdt.getDate());

Output: 2011-08-31

GlideDateTime - addYearsUTC(Number years)

Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.

The date and time value stored by GlideDateTime object is interpreted as being in the UTC time zone.

Table 29. Parameters
Name Type Description
years Number The number of years to add. Use a negative value to subtract.
Table 30. Returns
Type Description
void

Scoped equivalent

To use the addYearsUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - addYearsUTC(Number years).

var gdt = new GlideDateTime("2010-08-31 08:00:00");
gdt.addYearsUTC(1);
gs.print(gdt.getDate());

Output: 2011-08-31

GlideDateTime - compareTo(Object dateTime)

Compares two date and time objects to determine whether one occurs before the other or if they are equivalent.

Table 31. Parameters
Name Type Description
dateTime Object Date time in a GlideDateTime object
Table 32. Returns
Type Description
Number
  • 0 = Dates are equal
  • 1 = Initial date is before the compare date
  • -1 = Initial date is after the compare date

Scoped equivalent

To use the compareTo() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - compareTo(Object o).

var initDate = new GlideDateTime("2011-08-01 12:00:00");
var compDate1 = new GlideDateTime("2011-08-01 12:00:00");
var compDate2 = new GlideDateTime("2011-07-31 12:00:00");
var compDate3 = new GlideDateTime("2011-08-04 16:00:00");
 
gs.info(initDate.compareTo(compDate1)); // Equals
gs.info(initDate.compareTo(compDate2)); // Earlier than
gs.info(initDate.compareTo(compDate3)); // Later than

GlideDateTime - equals(Object GDT)

Compares an object with an existing value for equality.

Table 33. Parameters
Name Type Description
GDT Object The object to compare. Can be a GlideDateTIme object or a valid date time string.
Table 34. Returns
Type Description
Boolean True if they are equal, false otherwise.

Scoped equivalent

To use the equals() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - equals(Object dateTime).

var gdt = new GlideDateTime("2011-08-31 00:00:00");
gs.print(gdt.equals("2011-09-30 00:12:01"));

Output: false

GlideDateTime - getDate()

Gets the date stored by the GlideDateTime object, expressed in the standard format, yyyy-MM-dd, and the system time zone, UTC by default.

Table 35. Parameters
Name Type Description
None
Table 36. Returns
Type Description
GlideDate The date in the system time zone.

Scoped equivalent

To use the getDate() method in a scoped application, use the corresponding scoped method:Scoped GlideDateTime - getDate().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getDate());

Output: 2011-08-31

GlideDateTime - getDayOfWeek()

Gets the day of the week stored by the GlideDateTime object, expressed in the user's time zone.

Use getDayOfWeekLocalTime() and getDayOfWeekUTC() instead of this method.

Table 37. Parameters
Name Type Description
None
Table 38. Returns
Type Description
Number The day of the week value - Monday = 1, ... Sunday = 7.

var gdt = new GlideDateTime("2011-12-01 12:00:00");
gs.print(gdt.getDayOfWeek());

Output: 4

GlideDateTime - getDayOfMonth()

Gets the current day of the month in the UTC time zone.

Use getDayOfMonthLocalTime() and getDayOfMonthUTC() instead of this method.

Table 39. Parameters
Name Type Description
None
Table 40. Returns
Type Description
Number The day of the month in the UTC time zone, from 1 to 31.

var gdt = new GlideDateTime("2011-12-02 12:00:00");
gs.print(gdt.getDayOfMonth());

Output: 2

GlideDateTime - getDayOfMonthLocalTime()

Gets the day of the month stored by the GlideDateTime object, expressed in the current user's time zone.

Table 41. Parameters
Name Type Description
None
Table 42. Returns
Type Description
Number The day of the month in the user's time zone, from 1 to 31.

Scoped equivalent

To use the getDayOfMonthLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDayOfMonthLocalTime().

var gdt = new GlideDateTime("2011-12-02 12:00:00");
gs.print(gdt.getDayOfMonthLocalTime());

Output: 2

GlideDateTime - getDayOfMonthUTC()

Gets the day of the month stored by the GlideDateTime object, expressed in the UTC time zone.

Table 43. Parameters
Name Type Description
None
Table 44. Returns
Type Description
Number The day of the month in the UTC time zone, from 1 to 31.

Scoped equivalent

To use the getDayOfMonthUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDayOfMonthUTC().

var gdt = new GlideDateTime("2011-12-02 12:00:00");
gs.print(gdt.getDayOfMonthUTC());

Output: 2

GlideDateTime - getDayOfWeekLocalTime()

Gets the day of the week stored by the GlideDateTime object, expressed in the user's time zone.

Table 45. Parameters
Name Type Description
None
Table 46. Returns
Type Description
Number The day of the week value - Monday = 1, ... Sunday = 7

Scoped equivalent

To use the getDayOfWeekLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDayOfWeekLocalTime().

var gdt = new GlideDateTime("2011-12-01 12:00:00");
gs.print(gdt.getDayOfWeekLocalTime());

Output: 4

GlideDateTime - getDayOfWeekUTC()

Gets the day of the week stored by the GlideDateTime object, expressed in the UTC time zone.

Table 47. Parameters
Name Type Description
None
Table 48. Returns
Type Description
Number The day of the week value - Monday = 1, ... Sunday = 7

Scoped equivalent

To use the getDayOfWeekUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDayOfWeekUTC().

var gdt = new GlideDateTime("2011-12-01 12:00:00");
gs.print(gdt.getDayOfWeekUTC());

Output: 4

GlideDateTime - getDaysInMonth()

Gets the number of days in the month stored by the GlideDateTime object, expressed in the Java Virtual Machine time zone.

Use getDaysInMonthLocalTime() and getDaysInMonthUTC() instead of this method.

Table 49. Parameters
Name Type Description
None
Table 50. Returns
Type Description
Number The number of days in the current month in the Java Virtual Machine time zone.

var gdt = new GlideDateTime(); //December
gs.print(gdt.getDaysInMonth());

Output: 31

GlideDateTime - getDaysInMonthLocalTime()

Gets the number of days in the month stored by the GlideDateTime object, expressed in the current user's time zone.

Table 51. Parameters
Name Type Description
None
Table 52. Returns
Type Description
Number The number of days in the current month in the user's time zone.

Scoped equivalent

To use the getDaysInMonthLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDaysInMonthLocalTime().

var gdt = new GlideDateTime(); //December
gs.print(gdt.getDaysInMonthLocalTime());

Output: 31

GlideDateTime - getDaysInMonthUTC()

Gets the number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone.

Table 53. Parameters
Name Type Description
None
Table 54. Returns
Type Description
Number The number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone.

Scoped equivalent

To use the getDaysInMonthUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDaysInMonthUTC().

var gdt = new GlideDateTime(); //December
gs.print(gdt.getDaysInMonthUTC());

Output: 31

GlideDateTime - getDisplayValue()

Gets the date and time value in the current user's display format and time zone. Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.

Table 55. Parameters
Name Type Description
None
Table 56. Returns
Type Description
String The date and time in the user's format and time zone. Keep in mind when designing business rules or script includes that this method may return values in different formats for different users.

Scoped equivalent

To use the getDisplayValue() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDisplayValue().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getDisplayValue());

Output:

2011-08-31 01:00:00

GlideDateTime - getDisplayValueInternal()

Gets the display value in the internal format (yyyy-MM-dd HH:mm:ss). This method is useful for date/time fields, but not for date fields.

Table 57. Parameters
Name Type Description
None
Table 58. Returns
Type Description
String The date and time values for the GlideDateTime object in the current user's time zone and the internal date and time format of yyyy-MM-dd HH:mm:ss.

Scoped equivalent

To use the getDisplayValueInternal() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDisplayValueInternal().

// Wednesday
var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getDisplayValueInternal());

Output:

2011-08-31 01:00:00

GlideDateTime - getDSTOffset()

Gets the amount of time that daylight saving time is offset.

Table 59. Parameters
Name Type Description
None
Table 60. Returns
Type Description
Number Amount of time, in milliseconds, that daylight saving is offset. Returns 0 if there is no offset or if the time is not during daylight saving time.

Scoped equivalent

To use the getDSTOffset() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getDSTOffset().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getDSTOffset());

Output:

3600000

GlideDateTime - getErrorMsg()

Gets the current error message.

Table 61. Parameters
Name Type Description
None
Table 62. Returns
Type Description
String The error message

Scoped equivalent

To use the getErrorMsg() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getErrorMsg().

var gdt = new GlideDateTime("2011-08-31 aa:00:00"); //bad
gs.print(gdt.isValid()); //false
gs.print(gdt.getErrorMsg()); //reason
Output:
false
Could not parse DateTime: 2011-08-31 aa:00:00

GlideDateTime - getInternalFormatedLocalTime()

Returns the object's time in the local time zone and in the internal format.

Table 63. Parameters
Name Type Description
None
Table 64. Returns
Type Description
String The object's time in the local time zone and the internal format.

Scoped equivalent

To use the getInternalFormatedLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getInternalFormatedLocalTime().

GlideDateTime - getInternalMidnight(Number dayOfTheWeek)

Returns a date and time object set to midnight of a specified day using UTC.

Table 65. Parameters
Name Type Description
dayOfTheWeek Number The day of the week for which to return the date/time object.
Table 66. Returns
Type Description
GlideDateTime A GlideDateTime object set to midnight.

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getInternalMidnight(2));

Output: 2011-08-30 00:00:01

GlideDateTime - getLocalDate()

Gets the date stored by the GlideDateTime object, expressed in the standard format, yyyy-MM-dd, and the current user's time zone.

Table 67. Parameters
Name Type Description
None
Table 68. Returns
Type Description
GlideDate The date in the user's time zone.

Scoped equivalent

To use the getLocalDate() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getLocalDate().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getLocalDate());

Output: 2011-08-31

GlideDateTime - getLocalTime()

Gets the time in the user's time zone.

Table 69. Parameters
Name Type Description
None
Table 70. Returns
Type Description
GlideTime The time in the user's time zone.

Scoped equivalent

To use the getLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getLocalTime().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getLocalTime());

Output: 1970-01-01 01:00:00

GlideDateTime - getMonth()

Gets the month stored by the GlideDateTime object, expressed in Java Virtual Machine time zone.

Use getMonthLocalTime() and getMonthUTC() instead of this method.

Table 71. Parameters
Name Type Description
None
Table 72. Returns
Type Description
Number The numerical value of the month, Jan=1, Dec=12.

var gdt = new GlideDateTime(); //December
gs.print(gdt.getMonth());

Output: 12

GlideDateTime - getMonthLocalTime()

Gets the month stored by the GlideDateTime object, expressed in the current user's time zone.

Table 73. Parameters
Name Type Description
None
Table 74. Returns
Type Description
Number The numerical value of the month, Jan=1, Dec=12.

Scoped equivalent

To use the getMonthLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getMonthLocalTime().

var gdt = new GlideDateTime(); //December
gs.print(gdt.getMonthLocalTime());

Output: 12

GlideDateTime - getMonthUTC()

Gets the month stored by the GlideDateTime object, expressed in the UTC time zone.

Table 75. Parameters
Name Type Description
None
Table 76. Returns
Type Description
Number The numerical value of the month, Jan=1, Dec=12.

Scoped equivalent

To use the getMonthUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getMonthUTC().

var gdt = new GlideDateTime(); //December
gs.print(gdt.getMonthUTC());

Output: 12

GlideDateTime - getNumericValue()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT.

Table 77. Parameters
Name Type Description
None
Table 78. Returns
Type Description
Number The number of milliseconds since January 1, 1970, 00:00:00 GMT.

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getNumericValue());

Output: 1314777600000

GlideDateTime - getSpanTime(Number dayOfWeek)

Gets the amount of time elapsed since the midnight of a specified day to the current time.

Table 79. Parameters
Name Type Description
dayOfWeek Number Day of week value from 1 to 7. 1 = Monday, 7=Sunday.
Table 80. Returns
Type Description
GlideTime The amount of time elapsed since midnight of the specified day. To display the result in user-friendly terms, set the value to GlideDuration.

var gdt = new GlideDateTime("2011-08-31 08:00:00"); //Wednesday
var dur = new GlideDuration();
 
var span = gdt.getSpanTime(1); //how much time since Monday 00:00:00
dur.setValue(span);
gs.print(dur.getDisplayValue());

Output: 2 Days 8 Hours

GlideDateTime - getTime()

Gets the Unix duration stamp.

Table 81. Parameters
Name Type Description
None
Table 82. Returns
Type Description
GlideTime The Unix duration stamp in system format based on GMT time.

Scoped equivalent

To use the getTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getTime().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getTime());

Output: 1970-01-01 08:00:00

GlideDateTime - getTZOffset()

Gets the time zone offset in milliseconds.

Table 83. Parameters
Name Type Description
None
Table 84. Returns
Type Description
Number The number of milliseconds of the time zone offset

Scoped equivalent

To use the getTZOffset() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getTZOffset().

var gdt = new GlideDateTime();
gdt.getLocalTime(); // PST local time
gs.print(gdt.getTZOffset());

Output: -28800000

GlideDateTime - getUserFormattedLocalTime()

Returns the object's time in local time zone in the user's format.

Table 85. Parameters
Name Type Description
None
Table 86. Returns
Type Description
String The object's time in local time and the user's format.

Scoped equivalent

To use the getUserFormattedLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getUserFormattedLocalTime().

GlideDateTime - getUserTimeZone()

Gets the time zone for the current user session.

This method is equivalent to gs.getSession().getTimeZone().

Table 87. Parameters
Name Type Description
None
Table 88. Returns
Type Description
TimeZone TimeZone object for the current user.

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getUserTimeZone());

Output:

sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,
lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,
startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,
endTime=7200000,endTimeMode=0]]

GlideDateTime - getUTCMidnight(Number dayOfTheWeek)

Gets a GlideDateTime object with the time set to midnight using the UTC time zone.

This method sets the date of the new GlideDateTime object as the specified day of the week within the week of the original GlideDateTime object.

Table 89. Parameters
Name Type Description
dayOfTheWeek Number The day of the week, from 1 to 7. Monday=1, Sunday=7. Do not enter 0 in this parameter.
Table 90. Returns
Type Description
GlideDateTime A new GlideDateTime object, set to midnight.

var gdt = new GlideDateTime("2011-08-31 08:00:00"); // Wednesday, 3rd day of the week.
gs.print(gdt.getUTCMidnight(5)); //Friday, 5th day of the week.

Output: 2011-09-02 00:00:00

GlideDateTime - getValue()

Gets the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default.

Table 91. Parameters
Name Type Description
None
Table 92. Returns
Type Description
String The date and time in the internal format and system time zone.

Scoped equivalent

To use the getValue() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getValue().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.getValue());

Output:

2011-08-31 08:00:00

GlideDateTime - getWeekOfYearLocalTime()

Gets the number of the week stored by the GlideDateTime object, expressed in the current user's time zone.

All weeks begin on Sunday. The first week of the year is the week that contains at least one day of the new year. The week beginning Sunday 2015-12-27 is considered the first week of 2016 as that week contains January 1 and 2.

Table 93. Parameters
Name Type Description
None
Table 94. Returns
Type Description
Number The number of the current week. The highest week number in a year is either 52 or 53.

Scoped equivalent

To use the getWeekOfYearLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getWeekOfYearLocalTime().

var gdt = new GlideDateTime("2011-12-01 12:00:00");
gs.print(gdt.getWeekOfYearUTC());

Output: 49

GlideDateTime - getWeekOfYearUTC()

Gets the number of the week stored by the GlideDateTime object, expressed in the UTC time zone.

All weeks begin on Sunday. The first week of the year is the week that contains at least one day of the new year. The week beginning Sunday 2015-12-27 is considered the first week of 2016 as that week contains January 1 and 2.

Table 95. Parameters
Name Type Description
None
Table 96. Returns
Type Description
Number The number of the current week in UTC time. The highest week number in a year is either 52 or 53.

Scoped equivalent

To use the getWeekOfYearUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getWeekOfYearUTC().

var gdt = new GlideDateTime("2011-12-01 12:00:00");
gs.print(gdt.getWeekOfYearUTC());

Output: 49

GlideDateTime - getYear()

Gets the year stored by the GlideDateTime object, expressed in the Java Virtual Machine time zone.

Use getYearLocalTime() and getYearUTC() instead of this method.

Table 97. Parameters
Name Type Description
None
Table 98. Returns
Type Description
Number The 4-digit year value in the Java Virtual Machine time zone.

var gdt = new GlideDateTime(); //2011
gs.print(gdt.getYear());

Output: 2011

GlideDateTime - getYearLocalTime()

Gets the year stored by the GlideDateTime object, expressed in the current user's time zone.

Table 99. Parameters
Name Type Description
None
Table 100. Returns
Type Description
Number The 4-digit year value in the user's time zone.

Scoped equivalent

To use the getYearLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getYearLocalTime().

var gdt = new GlideDateTime(); //2011
gs.print(gdt.getYearLocalTime());

Output: 2011

GlideDateTime - getYearUTC()

Gets the year stored by the GlideDateTime object, expressed in the UTC time zone.

Table 101. Parameters
Name Type Description
None
Table 102. Returns
Type Description
number The 4-digit year value in the UTC time zone.

Scoped equivalent

To use the getYearUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - getYearUTC().

var gdt = new GlideDateTime(); //2011
gs.print(gdt.getYearUTC());

Output: 2011

GlideDateTime - GlideDateTime()

Instantiates a new GlideDateTime object with the current date and time in GMT format.

Table 103. Parameters
Name Type Description
None

var gdt = new GlideDateTime();

GlideDateTime - GlideDateTime(String dateTime)

Instantiates a new GlideDateTime object from a date and time value in the UTC time zone specified with the format yyyy-MM-dd HH:mm:ss.

Table 104. Parameters
Name Type Description
dateTime String A UTC date and time using the format yyyy-MM-dd HH:mm:ss.

var gdt = new GlideDateTime("2011-01-01 12:00:00");

GlideDateTime - GlideDateTime(GlideDateTime gDT)

Instantiates a new GlideDateTime object set to the time of a specified GlideDateTime object in GMT format.

Table 105. Parameters
Name Type Description
gDT GlideDateTime Object used to set the time of the new object.

var start = new GlideDateTime("2011-01-01 12:00:00");
var end = new GlideDateTime(start);
gs.print(end);

Output:

2011-01-01 12:00:00

GlideDateTime - hasDate()

Determines if an object's date is set.

Table 106. Parameters
Name Type Description
None
Table 107. Returns
Type Description
Boolean True if the object's date is set, false otherwise.

Scoped equivalent

To use the hasDate() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - hasDate().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.hasDate());

Output:

true

GlideDateTime - isDST()

Determines if the object's time uses a daylight saving offset

Table 108. Parameters
Name Type Description
None
Table 109. Returns
Type Description
Boolean True if the time is daylight saving time, false otherwise.

Scoped equivalent

To use the isDST() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - isDST().

var gdt = new GlideDateTime("2011-08-31 00:00:00");
gs.print(gdt.isDST()); //true

Output:

true

GlideDateTime - isValid()

Determines if a value is a valid date and time.

Table 110. Parameters
Name Type Description
None
Table 111. Returns
Type Description
Boolean True if value is valid, false otherwise.

Scoped equivalent

To use the isValid() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - isValid().

var gdt = new GlideDateTime("2011-08-31 aa:00:00"); //bad
gs.print(gdt.isValid()); //false

Output: false

GlideDateTime - setDisplayValue(String asDisplayed)

Sets a date and time value using the current user's display format and time zone.

Table 112. Parameters
Name Type Description
asDisplayed String The date and time in the current user's display format and time zone. The parameter must be formatted using the current user's preferred display format, such as MM-dd-yyyy HH:mm:ss. To assign the current date and time to a variable in a workflow script, use <variable>.setDisplayValue(gs.nowDateTime);.
Table 113. Returns
Type Description
void

Scoped equivalent

To use the setDisplayValue() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setDisplayValue(String asDisplayed).

var gdt = new GlideDateTime("2011-02-02 12:00:00");
gdt.setDisplayValue("2011-01-01 12:00:00");
gs.print(gdt.getValue());

Output:

2011-01-01 20:00:00

GlideDateTime - setDisplayValue(String dateTime, String format)

Sets a date and time value using the current user's time zone and the specified date and time format.

This method throws a runtime exception if the date and time format used in the dateTime parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught.

Table 114. Parameters
Name Type Description
dateTime String The date and time in the current user's time zone.
format String The format to use to parse the dateTime parameter.
Table 115. Returns
Type Description
void

Scoped equivalent

To use the setDisplayValue() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setDisplayValue(String value, String format).

var gdt = new GlideDateTime("2011-02-02 12:00:00");
gdt.setDisplayValue("20-5-2011 12:00:00", "dd-MM-yyyy HH:mm:ss");
gs.print(gdt.getValue());

Output:

2011-05-20 19:00:00

GlideDateTime - setDisplayValueInternal(String dateTime)

Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the current user's time zone.

Table 116. Parameters
Name Type Description
dateTime String The date and time in internal format
Table 117. Returns
Type Description
void

Scoped equivalent

To use the setDisplayValueInternal() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setDisplayValueInternal(String value).

var gdt = new GlideDateTime("2011-02-02 12:00:00");
gdt.setDisplayValueInternal("2011-01-01 12:00:00");
gs.print(gdt.getValue());

Output:

2011-01-01 20:00:00

GlideDateTime - setDisplayValueInternalWithAlternates(String dateTime)

Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the current user's time zone.

This method attempts to parse incomplete date and time values.

Table 118. Parameters
Name Type Description
dateTime String The date and time in internal format.
Table 119. Returns
Type Description
void


      
    

GlideDateTime - setGlideDateTime(GlideDateTime gDT)

Sets the date and time of the current object using an existing GlideDateTime object.

This method is equivalent to instantiating a new object with a GlideDateTime parameter.

Table 120. Parameters
Name Type Description
gDT GlideDateTime A GlideDateTime object
Table 121. Returns
Type Description
void

Scoped equivalent

To use the setGlideDateTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setGlideDateTime(GlideDateTime g).

var dt1 = new GlideDateTime("2011-01-01 12:00:00");
var dt2 = new GlideDateTime("2011-02-02 08:00:00");
dt1.setGlideDateTime(dt2);
gs.print(dt1.getValue());

Output:

2011-02-02 08:00:00

GlideDateTime - setTZ(TimeZone timeZone)

Sets the time zone of the GlideDateTime object to be the specified time zone.

Table 122. Parameters
Name Type Description
timeZone TimeZone A time zone object
Table 123. Returns
Type Description
void

var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime(); 
gdt.setTZ(tz);

GlideDateTime - setValue(Object dateTime)

Sets the date and time of the GlideDateTime object.

This method is equivalent to setInitialValue().

Table 124. Parameters
Name Type Description
dateTime Object The date and time to use. This parameter may be one of several types.
  • A string in the UTC time zone and the internal format of yyyy-MM-dd HH:mm:ss: Sets the value of the object to the specified date and time. Using the method this way is equivalent to instantiating a new GlideDateTime object using the GlideDateTime(value) constructor. If the date and time format used does not match the internal format, the method attempts to set the date and time using other available formats. Resolving the date and time this way can lead to inaccurate data due to ambiguity in the day and month values. When using a non-standard date and time format, use setValue(dt, format) instead.
  • A GlideDateTime object: Sets the value of the object to the date and time stored by the GlideDateTime passed in the parameter. Using the method this way is equivalent to instantiating a new GlideDateTime object using the GlideDateTime(g) constructor.
  • A Java Date object: Sets the value of the object using the value stored by the Java Date object. Using the method this way is equivalent to passing the value returned by the Java Date object getTime() to the GlideDateTime setNumericValue() method. This method does not accept JavaScript Date objects.
  • A JavaScript Number: Sets the value of the object using the Number value as milliseconds past January 1, 1970 00:00:00 GMT. Using the method this way is equivalent to the setNumericValue(milliseconds) method.
  • A Java Integer or Long: Sets the value of the object using the Integer or Long value as milliseconds past January 1, 1970 00:00:00 GMT. Using the method this way is equivalent to the setNumericValue(milliseconds) method.
Table 125. Returns
Type Description
void

Scoped equivalent

To use the setValue() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setValue(String o).

var gdt = new GlideDateTime("2011-01-01 12:00:00");
gdt.setValue("2011-02-02 08:00:00");
gs.print(gdt.getValue());

Output:

2011-02-02 08:00:00

GlideDateTime - setValueUTC(String dateTime, String format)

Sets a date and time value using the UTC time zone and the specified date and time format.

This method throws a runtime exception if the date and time format used in the dateTime parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught.

Table 126. Parameters
Name Type Description
dateTime String The date and time to use.
format String The format to use.
Table 127. Returns
Type Description
void

Scoped equivalent

To use the setValueUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setValueUTC(String dt, String format).

var gdt = new GlideDateTime("2011-01-01 12:00:00");
gdt.setValueUTC("15-02-2011 08:00:00", "dd-MM-yyyy HH:mm:ss");
gs.print(gdt.getValue());

Output:

2011-02-15 08:00:00

GlideDateTime - setDayOfMonth(Number day)

Sets the day of the month to a specified value.

Use setDayOfMonthLocalTime(day) and setDayOfMonthUTC(day) instead of this method.

Table 128. Parameters
Name Type Description
day Number Day of the month, from 1 to 31.
Table 129. Returns
Type Description
void

var gdt = new GlideDateTime();
gdt.setDayOfMonth(9);
gs.print(gdt.getDayOfMonth());

Output: 9

GlideDateTime - setDayOfMonthLocalTime(Number day)

Sets the day of the month to a specified value in the current user's time zone.

Table 130. Parameters
Name Type Description
day Number The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month.
Table 131. Returns
Type Description
void

Scoped equivalent

To use the setDayOfMonthLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setDayOfMonthLocalTime(Number day).

var gdt = new GlideDateTime();
gdt.setDayOfMonthLocalTime(9);
gs.print(gdt.getDayOfMonthLocalTime());

Output: 9

GlideDateTime - setDayOfMonthUTC(Number day)

Sets the day of the month to a specified value in the UTC time zone.

Table 132. Parameters
Name Type Description
day Number The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month.
Table 133. Returns
Type Description
void

Scoped equivalent

To use the setDayOfMonthUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setDayOfMonthUTC(Number day).

var gdt = new GlideDateTime();
gdt.setDayOfMonthUTC(9);
gs.print(gdt.getDayOfMonthUTC());

Output: 9

GlideDateTime - setInitialValue(String dateTime)

Sets the date and time.

This method is equivalent to setValue(Object).

Table 134. Parameters
Name Type Description
dateTime String The date and time to use. Accepts either a string in the GMT time zone in the internal format, or a GlideDateTime object.
Table 135. Returns
Type Description
void

var gdt = new GlideDateTime();
gdt.setInitialValue("2011-01-01 12:00:00");
gs.print(gdt.getValue());

Output: 2011-01-01 12:00:00

GlideDateTime - setMonth(Number month)

Sets the month stored by the GlideDateTime object to a specified value using the Java Virtual Machine time zone.

Use setMonthLocalTime() or setMonthUTC() instead of this method.

Table 136. Parameters
Name Type Description
month Number The month to change to.
Table 137. Returns
Type Description
void

var gdt = new GlideDateTime();
gdt.setMonth(1);
gs.print(gdt.getMonth());

Output: 1

GlideDateTime - setMonthLocalTime(Number month)

Sets the month stored by the GlideDateTime object to a specified value using the current user's time zone.

Table 138. Parameters
Name Type Description
month Number The month to change to.
Table 139. Returns
Type Description
void

Scoped equivalent

To use the setMonthLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setMonthLocalTime(Number month).

var gdt = new GlideDateTime();
gdt.setMonthLocalTime(1);
gs.print(gdt.getMonthLocalTime());

Output: 1

GlideDateTime - setMonthUTC(Number month)

Sets the month stored by the GlideDateTime object to a specified value using the UTC time zone.

Table 140. Parameters
Name Type Description
month Number The month to change to.
Table 141. Returns
Type Description
void

Scoped equivalent

To use the setMonthUTC() method in a scoped application, use the corresponding scoped method:Scoped GlideDateTime - setMonthUTC(Number month).

var gdt = new GlideDateTime();
gdt.setMonthUTC(1);
gs.print(gdt.getMonthUTC());

Output: 1

GlideDateTime - setNumericValue(Number milliseconds)

Sets the date and time to the number of milliseconds since January 1, 1970 00:00:00 GMT.

Table 142. Parameters
Name Type Description
milliseconds Number The number of milliseconds
Table 143. Returns
Type Description
void

var gdt = new GlideDateTime();
gdt.setNumericValue(1314777600000);
gs.print(gdt.getValue());

Output: 2011-08-31 08:00:00

GlideDateTime - setYear(Number year)

Sets the year stored by the GlideDateTime object to a specified value using the Java Virtual Machine time zone.

Use setYearLocalTime() or setYearUTC() instead of this method.

Table 144. Parameters
Name Type Description
year Number The year to change to.
Table 145. Returns
Type Description
void

var gdt = new GlideDateTime();
gdt.setYear(2013);
gs.print(gdt.getYear());

Output: 2013

GlideDateTime - setYearLocalTime(Number year)

Sets the year stored by the GlideDateTime object to a specified value using the current user's time zone.

Table 146. Parameters
Name Type Description
year Number The year to change to.
Table 147. Returns
Type Description
void

Scoped equivalent

To use the setYearLocalTime() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setYearLocalTime(Number year).

var gdt = new GlideDateTime();
gdt.setYearLocalTime(2013);
gs.print(gdt.getYearLocalTime());

Output: 2013

GlideDateTime - setYearUTC(Number year)

Sets the year stored by the GlideDateTime object to a specified value using the UTC time zone.

Table 148. Parameters
Name Type Description
year Number The year to change to.
Table 149. Returns
Type Description
void

Scoped equivalent

To use the setYearUTC() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setYearUTC(Number year).

var gdt = new GlideDateTime();
gdt.setYearUTC(2013);
gs.print(gdt.getYearUTC());

Output: 2013

GlideDateTime - subtract(GlideTime time)

Subtracts a specified amount of time.

Table 150. Parameters
Name Type Description
time GlideTime The time to subtract
Table 151. Returns
Type Description
void

Scoped equivalent

To use the subtract() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - subtract(GlideTime time).

var gdt = new GlideDateTime("2011-08-31 08:00:00");
var gtime1 = new GlideTime();
gtime1.setValue("00:00:20");
gdt.subtract(gtime1);
gs.print(gdt.getTime());

Output: 1970-01-01 07:59:40

GlideDateTime - subtract(Number milliseconds)

Subtracts a specified number of milliseconds from the GlideDateTime object.

Table 152. Parameters
Name Type Description
milliseconds Number The number of milliseconds to subtract
Table 153. Returns
Type Description
void

Scoped equivalent

To use the subtract() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - subtract(Number milliseconds).

var gdt = new GlideDateTime("2011-12-07 08:00:00");
gdt.subtract(1000);
gs.print(gdt.getValue());

Output: 2011-12-07 07:59:59

GlideDateTime - subtract(GlideDateTime start, GlideDateTime end)

Gets the duration difference between two GlideDateTime values.

Table 154. Parameters
Name Type Description
start GlideDateTime The start value
end GlideDateTime The end value
Table 155. Returns
Type Description
GlideDuration The time between the two values

Scoped equivalent

To use the subtract() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - subtract(GlideDateTime start, GlideDateTime end).

var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
var dur = new GlideDuration();
 
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
gs.print(dur.getDisplayValue());

Output: 2 Days 23 Hours

GlideDateTime - toString()

Gets the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default.

This method is equivalent to getValue().

Table 156. Parameters
Name Type Description
None
Table 157. Returns
Type Description
String The date and time stored by the GlideDateTime object in the system time zone and format.

Scoped equivalent

To use the toString() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - toString().

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.print(gdt.toString());

Output: 2011-08-31 08:00:00