The CreatorCon Call for Content is officially open! Get started here.

Need help on remove Seconds from Date/time field.

Jessica28
Tera Guru

Hello,

We have a Start Date/Time variable on a Catalog Item like this:

Jessica28_1-1694636506890.png

 

Below screenshot was from a email script.  How to remove seconds from time?

 

Jessica28_0-1694636361058.png

 

Thank you

1 ACCEPTED SOLUTION

 

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".

View solution in original post

10 REPLIES 10

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"

 

https://www.servicenow.com/community/developer-forum/how-to-set-seconds-to-00-and-round-to-quarter-h...

 

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.

 

 

Saurabh Gupta
Kilo Patron

Hi @Jessica28 ,
You can do the string manipulation here.


Thanks and Regards,

Saurabh Gupta

RAMANA MURTHY G
Mega Sage

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.

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Jessica28
Tera Guru

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.

 

 

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".