Created
August 5, 2022 11:23
-
-
Save ovarn/1721071e223a08e7c0344f9e91089488 to your computer and use it in GitHub Desktop.
A cheat sheet for working with the ServiceNow Date and Date/Time fields on the client side.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Display value | |
| var dateStr = g_form.getValue('<date_field_name>'); | |
| // Display value => milliseconds | |
| var ms = getDateFromFormat(dateStr, g_user_date_format); | |
| // Milliseconds => JS Date instance | |
| var date = new Date(ms); | |
| // JS Date instance => display value | |
| formatDate(date, g_user_date_format) === dateStr; // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Display value | |
| var dateTimeStr = g_form.getValue('<date_time_field_name>'); | |
| // Display value => milliseconds | |
| var ms = getDateFromFormat(dateTimeStr, g_user_date_time_format); | |
| // Milliseconds => JS Date instance | |
| var date = new Date(ms); | |
| // JS Date instance => display value | |
| formatDate(date, g_user_date_time_format) === dateTimeStr; // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment