- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 01:25 PM
Hello,
We have a Start Date/Time variable on a Catalog Item like this:
Below screenshot was from a email script. How to remove seconds from time?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 05:40 PM - edited 09-14-2023 05:43 PM
var strTime = "0:4:00:00 PM";
var spacePos = strTime.indexOf(" ");
var firstPart = strTime.substring(0, spacePos-3);
var lastPart = strTime.substring(spacePos);
gs.info('spacePos = ' + spacePos + ', firstPart = ' + firstPart + ', lastPart = ' + lastPart);
strTime = firstPart + lastPart;
gs.info('strTime = ' + strTime);
You can use logic in lines 2 -6 without the 'gs.info()' line. Parse on the space since hours and minutes can be single digits. the above results in " strTime = 0:4:00 PM".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 09:02 AM
Hello @Bert_c1
I got it to work by using the link you provided. All I did was changed the variable name "planned_start_date" to our variable name "select_start_date_and_time"
I did tried what Ramana Murthy suggested to modify System Properties > System > Time Format
and remove "ss" from format and you are correct that affects all DateTime displays in our instance.
We are looking to remove Seconds for just one DateTime variable or on the email notification.
Thank you so much for everyone suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 09:17 PM
Hi @Jessica28 ,
You can do the string manipulation here.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 09:55 PM
Hello @Jessica28 ,
Have you tried with System Properties > System > Time Format
and remove "ss" from format Hope this will help you.
mark my answer helpful, if it is correct.
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 03:29 PM
Hello,
I'm still trying to remove seconds (00) from the time variable.
The email script variable "strTime" holds the time format like this "0:4:00:00 PM"
If someone have a good experience in JavaScript, please suggest on how to remove the seconds from the time.
Start removing from second conlon ":00" that should works.
I tried using "substring method", but that did not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 05:40 PM - edited 09-14-2023 05:43 PM
var strTime = "0:4:00:00 PM";
var spacePos = strTime.indexOf(" ");
var firstPart = strTime.substring(0, spacePos-3);
var lastPart = strTime.substring(spacePos);
gs.info('spacePos = ' + spacePos + ', firstPart = ' + firstPart + ', lastPart = ' + lastPart);
strTime = firstPart + lastPart;
gs.info('strTime = ' + strTime);
You can use logic in lines 2 -6 without the 'gs.info()' line. Parse on the space since hours and minutes can be single digits. the above results in " strTime = 0:4:00 PM".