Formatting a Date in Calculated Field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 11:39 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 01:50 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 02:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2023 04:30 PM
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
Maybe others here have a suggestion for you.