- 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-13-2023 02:42 PM - edited 09-13-2023 02:54 PM
Hi jessica28,
I found this link when viewing your post:
We the author states: "I've also set it up to use an onLoad script to store my functions then simply call those functions from an onChange script tied to my start time and duration fields."
You can the 'roundStartTime()' function there for your "Start / Date Time" variable in a Catalog Client Script it seems.
But then, this won't help with the display of the value on the form if you don't want seconds shown.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 02:54 PM
Thank you for sharing your finding @Bert_c1
Let me give it a try and provide feedback.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 08:52 PM
Hi @Bert_c1
I have tried the suggestion codes and it rounds seconds to 00 and minutes to the nearest quarter hour.
However, it is still showing the seconds on the email notification. Is it possible to remove the seconds completely from the output. I'm very weak at JavaScript to be able to modify the code to remove it. Can you or someone help? Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 07:04 AM
Hi @Jessica28,
I tried a test in my instance, on a DateTime field, but didn't get it to work with just one function in the 'onLoad' client script to set the seconds to '00' and calling that function in an 'onChange' client script. Seems you were successful getting the example to work, but you didn't post either script. So I can't advise on how to just set the seconds to "00" with out the rounding.
Now, on eliminating the ":00" seconds from the form value, I can't help with that.
And changing the Time Format system property mentioned below will affect all DateTime display values in your instance. I believe you only want seconds removed for the one field on the form. Or is it just what is displayed in an "email notification". If so, I believe other Community members can help with that.