Formatting date in SharePoint API REST query result

You are using ShortPoint REST API Connection Type and you would want to format the date returned in a proper readable format for end users instead of showing it in ISO format.



For demo in this article, we have used Modified column but this article is not limited to Modified column only, you can use this solution for any date column you want.


Step 1

Connect to SharePoint REST API


Add ShortPoint to your page and use REST API connection type in your connect tab


To demonstrate in article, we have used Icon lists and ShortPoint and following REST API


https://lionsschools.sharepoint.com/sites/SCAC4/_api/web/lists/getByTitle('Documents')/items?$select=Modified,FileLeafRef


The date we are going to format is Modified column.


Step 2

Format the date result using Map Results feature


Now is the time to do the magic of changing the date format to the way we want. By default, you would see the result like below:


Lets go ahead and enable the Advanced Settings and format the date using custom code:



the code you see in above screenshot is as below:


var moment = shortpoint.base.libs.moment;
data.d.results.forEach(function(item) {
item.Modified = moment(item.Modified).format('LLL');
});
return data;


Please be ware that since we have used Modified column we have used this line in the code:


item.Modified = moment(item.Modified).format('LLL');


However, if you have any other column to be formatted, please change above line and replace Modified with your own column name. You can also format multiple columns as follows


var moment = shortpoint.base.libs.moment;
data.d.results.forEach(function(item) {
item.DateColumn1 = moment(item.DateColumn1).format('LLL');
item.DateColumn2 = moment(item.DateColumn2).format('LLL');
});
return data;


Click on connect. You are done!


Here is an animation of steps you need to perform