- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ01-18-2022 01:21 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ01-18-2022 01:55 AM
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ01-18-2022 01:55 AM
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ01-18-2022 02:48 AM
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.