- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 07:49 AM
I'm passing over the value from the time_worked field via g_scratchpad but noticed it is also passing over a placeholder date (e.g 1970-01-01 01:00:00).
g_scratchpad.savedTime = current.time_worked;
Is there a easy way to simply remove the date so that the passed over value is just "01:00:00"?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 07:59 AM
Hi @MBarrott
g_scratchpad.savedTime = current.time_worked.toString().split(" ")[1];
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers
Thanks,
Sejal
Thanks & Regards
Sejal Chavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 08:02 AM - edited 10-24-2024 08:04 AM
Hi @MBarrott,
When dealing with date and time fields, don't forget timezones also need to be considered.
Rather than reinvent the wheel, here's a great article from @tiagomacul who provides both context and examples - Kudos.
Take a look - https://www.servicenow.com/community/developer-articles/scripts-how-to-get-only-hour-on-date-time-fi...
However, just in case links break in the future - here's a sample of the script the article provides when using a sample date "2021-03-08 16:24:06":
function timenow()
{
var gdttime = new GlideDateTime(current.time_worked);
var time = gdttime.getTime();
var timeCreated = time.getByFormat('HH:mm:ss');
return timeCreated;
}
gs.log("UDT time now = " + timenow());
Sample result "16:24:06"
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 09:36 AM
Thanks for sharing