The CreatorCon Call for Content is officially open! Get started here.

Please tell me about formatDate ().

Kurumi
Tera Contributor

I want to set the acquired date in the specified format in the client script. During my research, I found the function "formatDate ();" used in the link below.

ใƒปhttps://community.servicenow.com/community?id=community_question&sys_id=3870aca4db083490fb1e0b55ca961986&view_source=searchResult
ใƒปhttps://community.servicenow.com/community?id=community_question&sys_id=de3ac9dcdb4f80104819fb243996194c&view_source=searchResult
ใƒปhttps://community.servicenow.com/community?id=community_question&sys_id=410070aedbf0f340fff8a345ca961993


Please tell me about this formatDate () ;.
ใƒป Is this defined by servicenow? Is it defined in JavaScript?
ใƒปPlease let me know if there is a page or reference that explains the details.

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi Kurumi,

formatDate is a ServiceNow provided function. It isn't actually documented but I did do a bit of documentation for the Hacktoberfest Dev piece

code-snippets/Date Management.js at main ยท ServiceNowDevProgram/code-snippets (github.com)

View solution in original post

2 REPLIES 2

Kieran Anson
Kilo Patron

Hi Kurumi,

formatDate is a ServiceNow provided function. It isn't actually documented but I did do a bit of documentation for the Hacktoberfest Dev piece

code-snippets/Date Management.js at main ยท ServiceNowDevProgram/code-snippets (github.com)

Hitoshi Ozawa
Giga Sage
Giga Sage

It's a ServiceNow client script function.

var <string> = formatDate(<variable of Date type>, <date format>);

Format seems to be format allowed in Java's SimpleDateFormat.

https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Often, another ServiceNow client script variable, g_user_date_time_format format or g_user_date_format, is used to obtain the current user's date format. As the name suggests, g_user_date_time_format is format of date/time while g_user_date_format is format of date.

There is also getDateFromFormat(). This returns a timestamp. That is, number of seconds from 1970/1/1 00:00:00

var <int> = getDateFromFormat(<variable of Date type>, <date format>);

When doing date calculation on the client side, care must be taken if Daylight time saving time is used in the timezone. GlideDateTime takes care of the Daylight saving calculation but client script would need to implement it if required or use GlideAjax() to call script include to do the calculation on the server.