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

Hi Joakim,



I don't think there's any way to change the date format that comes back in the REST API response. Instead it should be simple to use a regex to extract the parts of the date string that you want, for example:


var inc_opened_at = "2015-11-10 23:44:21";


var yymmdd = inc_opened_at.match(/\d{2}-\d{2}-\d{2}/);


gs.print(yymmdd);



This gives the output: 15-11-10



Please try it and let me know if that helped.


Hello Tim,



I am familiar with javascript but yet to learn how to do the above in servicenow, care to elaborate?


tim210
ServiceNow Employee
ServiceNow Employee

Hi Joakim,



As far as I can see you can't change the date/time format that comes through in JSON data from the REST API. That means you need to do the date/time format conversion (from yyyy-mm-dd hh:mm:ss to yy-mm-dd) in whatever program or script you're using to make the REST API calls.



I gave an example in Javascript since that's the most commonly used scripting language with ServiceNow, but you could easily do the same in Python, Ruby or whatever else you're using to process the data from the REST API calls.


Ok sure, I see what you mean now. The only problem with that is that I will get one response per timestamp, which might be a lot of data in the end. This is why I was hoping to use the aggregated API to tidy things up.