Date format in rest API response

oceansmoving
Kilo Explorer

API: Aggregated table

Table: Incident_SLA

When I return 'inc_opened_a', is it possible to format the date differently in the query?

Current format: yyyy-mm-dd hh:mm:ss

Preferred format: yy-mm-dd

Reason is, that I would like to aggregate and response based on date, and not date + time

10 REPLIES 10

tim210
ServiceNow Employee
ServiceNow Employee

I just did another test using the sysparm_display_value=true parameter to the REST API (ServiceNow KB: Resolving Date/Time Display Discrepancies in Web Services (KB0546240) ). It looks like it is possible to change the date format after all, although you can't get rid of the time component - if you don't need it you'll still have to filter that out in a script. Details:


- open the User[sys_user] record of the user you login as when doing REST API calls


- right-click Date format->Configure Choices


- in the 'slushbucket' screen add the yy-mm-dd date format (I don't think it's there by default), click save


- back on the User record select yy-mm-dd as the Date format


- run a REST API call, e.g. GET https://instance.service-now.com/api/now/table/incident_sla?sysparm_display_value=true&sysparm_limit...



The resulting JSON will include date/times like this:


"inc_activity_due": "16-02-23 08:37:49",


Hope that helps, sorry I didn't realise this sysparm_display_value parameter could be used like this before


I just had the opposite experience. I am on Tokyo version. When I used the sysparm_display_value=true, the REST API response has time with this format:

sys_created_on: 

03-22-2023 8:33:19 AM

When I removed sysparm_display_value=true, the REST API response has time in this format:

sys_created_on: 

 

2023-03-22 15:33:19

 

Yes, it would be nice if ServiceNow just use the RFC-3339 date format in UTC. 

I had the opposite problem than what you described. 

 

When I used the sysparm_display_value, my time format from the REST API response is like this:
sys_created_on: 

03-22-2023 8:33:19 AM

When I removed the sysparm_display_value=true from my request, the time format from the REST API response is like this: 

sys_created_on: 

2023-03-22 15:33:19

 which is more what I want. 

I agree with Daniel Gurney that the time format should just be RFC-3339 format in UTC timezone. 

vab_13
ServiceNow Employee
ServiceNow Employee

There is a property called: glide.sys.date_format which specifies the default system format, you can change that.




tim210
ServiceNow Employee
ServiceNow Employee

I just tested that on an Istanbul instance by changing glide.sys.date_format to yy-MM-dd. It had no effect on the format of the dates in the REST API response, e.g. I still get "inc_closed_at": "2015-11-10 23:44:21"