Trần Trung Trần Trung - 3 months ago 39
Ajax Question

Get only date without time from REST query on Sharepoint 2013

I have a date column on a Custom List. The format of that column can be set on Edit Column Page and it displays only date as expected on my Custom List page. But then I want to create a REST query by using ajax and display it on console log for debugging. The date is display as follow:

Date_x0020_Borrow:"2016-08-08T17:00:00Z"


Are there any ways to make it return only mm/dd/yyyy?

Answer

I don't know that api but you can easly parse date with plain JavaScript.

var date_tz = "2016-08-08T17:00:00Z";
f_z =  function(v) { if(parseInt(v) < 10) return "0"+v; return $v;}; // filling with 0 if needed

var d = new Date(date_tz);
d = f_z(d.getDate()) + '/' + f_z((d.getMonth()+1)) + '/' + d.getFullYear();

alert(d); // "08/08/2016"
Comments