- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2025 07:12 AM
I'd like to get today's date using a client script.
If anyone knows how, please let me know.
The conditions are as follows:
・Get in Japan time(JST)
・Get in yyyymmdd format
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2025 07:40 AM
Hi,
You can easily get and display the users time through the javascript Date() object.
A simple example:
var date = new Date();
g_form.addInfoMessage('Current date: ' + date.getFullYear() + (date.getMonth()+1) + date.getDate());
// the +1 to the month is because the months are numbered as 0-11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2025 09:56 AM - edited 08-20-2025 09:57 AM
Scenario 2: Prevent form submission if the entered date (in JST-normalized format) is in the past.
function onSubmit() {
var value = g_form.getValue('your_date_field');
if (!value) return true;
// Parse 'yyyyMMdd' into JS Date
var year = parseInt(value.substring(0, 4), 10);
var month = parseInt(value.substring(4, 6), 10) - 1;
var day = parseInt(value.substring(6, 8), 10);
var enteredDate = new Date(year, month, day);
var now = new Date();
now.setHours(0, 0, 0, 0);
var jstNow = new Date(now.getTime() + 9 * 60 * 60 * 1000);
jstNow.setHours(0, 0, 0, 0);
if (enteredDate < jstNow) {
g_form.addErrorMessage("The date cannot be in the past (JST).");
return false;
}
return true;
}
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/