Question on timezone formatting for a function field

MHager
Tera Contributor

I have an issue with a function field that is configured to take a Date/Time field value and just take the date and set that as the value. The function definition is currently "glidefunction:substring(planned_start,0,11)".

 

The problem occurs when a Date/Time field has a time on or after 16:00 hours, the function field will then display the date as the next calendar day. As an example, 2026-06-01 19:00 becomes 2026-06-02 in the function field.

 

I believe that this is due to a difference in UTC vs local time. Is there a better way to do this, or a more specific glidefunction script?

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @MHager 

 

Can you share your full code.

For functional field glidefunction:substring  - return type is String. Hope you have parsed with  date and time.

If your instance default is UTC, then difference should be in UTC.

 

Alternative 1 :  refer: How to extract Date from Date/Time field 

use following code snippet:

var gdt = new GlideDateTime(current.sys_created_on);

var date = gdt.getLocalDate();

 

Alternative 2 : Refer:https://www.servicenow.com/community/csm-forum/get-time-part-from-a-date-time-field/m-p/384890

var dateTimefield = g_form.getValue('<your_datetime_field>');

var dateArr = dateTimefield.split(' ');

var time = dateArr[1];//Return time

var date = dateArr[0];//Return Date

var date = gdt.getLocalDate();

 

 

 

Refer:

Use of function field in ServiceNow 

 https://www.youtube.com/watch?v=dppCE-UYqRc&t=134s

Functional Field on Report for Time Zone 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

2 REPLIES 2

Tanushree Maiti
Tera Patron

Hi @MHager 

 

Can you share your full code.

For functional field glidefunction:substring  - return type is String. Hope you have parsed with  date and time.

If your instance default is UTC, then difference should be in UTC.

 

Alternative 1 :  refer: How to extract Date from Date/Time field 

use following code snippet:

var gdt = new GlideDateTime(current.sys_created_on);

var date = gdt.getLocalDate();

 

Alternative 2 : Refer:https://www.servicenow.com/community/csm-forum/get-time-part-from-a-date-time-field/m-p/384890

var dateTimefield = g_form.getValue('<your_datetime_field>');

var dateArr = dateTimefield.split(' ');

var time = dateArr[1];//Return time

var date = dateArr[0];//Return Date

var date = gdt.getLocalDate();

 

 

 

Refer:

Use of function field in ServiceNow 

 https://www.youtube.com/watch?v=dppCE-UYqRc&t=134s

Functional Field on Report for Time Zone 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

This is the full code in the Function Definition of the field: glidefunction:substring(planned_start,0,11)

MHager_0-1780598632946.png

 

This does meet the criteria for essentially stripping the time out of the Date/Time field (planned_start), and will show only the date in the function field. 2026-06-01 19:00 becomes 2026-06-02

 

The issue that I'm trying to solve for is making sure that date is displayed in the local timezone since any time there is a date/time value in "planned_start" where the time is 16:00 or later, the function field returns the next day, since that's what it would be using UTC time. 

 

Are function fields capable of additional variables like changing the date/time to local time to avoid these UTC rollovers to a new day?