Formatting a Date in Calculated Field

Velma
Tera Guru

I have a date-time value in a field. I want to populate a second field with a simpler display value of that date-time. (Basically, leave out the final colon and the seconds. The seconds are irrelevant and make it harder to read and primarily take up way too much screen real estate in a view.) I thought I should be able to do that fast client side using current.[datetime]. But I can't figure out how to get a string for parsing out of the datetime client-side without it coming out UTC. Is there a way? 

 

If I use GlideDateTime it becomes easy, but that is a server call, I believe. In which case I should probably just be using a business rule? If I do use a business rule, what is a way to populate the field in existing data? 

3 REPLIES 3

Bert_c1
Kilo Patron
var curDate = new GlideDateTime();
var dateVal = curDate.toString();
gs.info(dateVal);
var newDate = dateVal.substring(0,16);
gs.info(newDate);

You can convert a value to a string as in the above, and use javascript's substring() method. Do that client side or server side.

 

I wonder what time zone value you will use, so that the new value is meaningful to all of you users.

Thank you. If I use GlideDateTime, I'm making a server call for each displayed record, unless I'm mistaken. Server calls are exactly what I'm trying to avoid. I'm trying to figure out how to get the displayed value from the field I'm referencing using current.[fieldname] without it getting converted to UTC. 

 

Bert_c1
Kilo Patron

It's not clear what you want. it seems you don't want a value that is UTC. please refer to:

https://www.servicenow.com/community/in-other-news/the-secrets-of-glidedatetime/ba-p/2290801

and

https://www.servicenow.com/community/developer-blog/date-and-time-fields-on-the-apps-and-clients/ba-...

 

Maybe others here have a suggestion for you.