- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2020 06:09 AM
Hi All,
How to set the date time with the help of client scripts?
Is it possible to ser date and time without using Ajax call in the client script?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2020 06:30 AM
With this simple client script code we can set date and time to the Date/Time type field or variable
function onLoad() {
var dt = formatDate(new Date(), g_user_date_time_format);
alert(dt);
g_form.setValue("u_date", dt);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2020 06:12 AM
Hi there,
Here's some nice reading for you:
https://www.servicenowguru.com/scripting/client-scripts-scripting/client-side-dates-in-servicenow/
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2020 06:22 AM
Hi,
Refer to this link where i have shown how to use date validations in the client script with examples.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2020 06:30 AM
With this simple client script code we can set date and time to the Date/Time type field or variable
function onLoad() {
var dt = formatDate(new Date(), g_user_date_time_format);
alert(dt);
g_form.setValue("u_date", dt);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 11:32 PM
Thanks for the solution. I am new to NOW platform and the code snippet above worked for me.