GlideDate - Scoped

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

Scoped GlideDate - getByFormat(String format)

Gets the date in the specified date format.

Table 1. Parameters
Name Type Description
format String the desired date format
Table 2. Returns
Type Description
String the date in the specified format
var gd = new GlideDate(); 
gd.setValue('2015-01-01');
gs.info(gd.getByFormat("dd-MM-yyyy"));

Output: 01-01-2015

Scoped GlideDate - getDisplayValue()

Gets the date in the current user's display format and time zone.

Table 3. Parameters
Name Type Description
none
Table 4. Returns
Type Description
String The date 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.
var gd =new GlideDate(); 
gd.setValue('2015-01-01');
gs.info(gd.getDisplayValue());

Output: 2015-01-01

Scoped GlideDate - getDisplayValueInternal()

Gets the display value in the internal format (yyyy-MM-dd).

Table 5. Parameters
Name Type Description
none
Table 6. Returns
Type Description
String The date values for the GlideDate object in the current user's time zone and the internal time format of yyyy-MM-dd.
var gd =new GlideDate(); 
gs.info(gd.getDisplayValueInternal());

Output: 2014-10-22

Scoped GlideDate - getValue()

Gets the date value stored in the database by the GlideDate object in the internal format, yyyy-MM-dd, and the system time zone, UTC by default.

Table 7. Parameters
Name Type Description
none
Table 8. Returns
Type Description
String The date value in the internal format and system time zone.
var gd =new GlideDate();
gd.setValue('2015-01-01');
gs.info(gd.getValue());

Output: 2015-01-01

Scoped GlideDate - GlideDate()

Instantiates a GlideDate object with the current datetime.

Table 9. Parameters
Name Type Description
None

    

Scoped GlideDate - setDisplayValue(String asDisplayed)

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

Table 10. Parameters
Name Type Description
asDisplayed String The date 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 yyyy-MM-dd.
Table 11. Returns
Type Description
void
var gd =new GlideDate();
gd.setDisplayValue("2011-01-01");
gs.info(gd.getValue());

Output: 2011-01-01

Scoped GlideDate - setValue(String o)

Sets the date of the GlideDate object.

Table 12. Parameters
Name Type Description
o String The date and time to use.
Table 13. Returns
Type Description
void
var gd = new GlideDate(); 
gd.setValue('2015-01-01');
gs.info(gd.getValue());

Output: 2015-01-01

Scoped GlideDate - subtract(GlideDate start, GlideDate end)

Gets the duration difference between two GlideDate values.

Table 14. Parameters
Name Type Description
start GlideDate The start value.
end GlideDate The end value.
Table 15. Returns
Type Description
GlideDuration The duration between the two values.
var sgd1 = new GlideDate(); 
sgd1.setDisplayValue('2014-07-18'); 
var sgd2 = new GlideDate(); 
sgd2.setDisplayValue('2014-07-19'); 
 
duration= GlideDate.subtract(sgd1, sgd2); 
gs.info(duration.getDisplayValue());

Output: 1 Day