Tuesday, January 21, 2014

convertSPDate by Ben Tedder

function convertSPDate(d) {
/*
*  A function to convert a standard SharePoint
* date/time field (YYYY-MM-DD HH:MM:SS) to a
* javascript Date() object
*
*/
    // split apart the date and time
var xDate = d.split(" ")[0];
var xTime = d.split(" ")[1];
 
    // split apart the hour, minute, & second
var xTimeParts = xTime.split(":");
var xHour = xTimeParts[0];
var xMin = xTimeParts[1];
var xSec = xTimeParts[2];
 
    // split apart the year, month, & day
var xDateParts = xDate.split("-");
var xYear = xDateParts[0];
var xMonth = xDateParts[1];
var xDay = xDateParts[2];
var dDate = new Date(xYear, xMonth, xDay, xHour, xMin, xSec);
return dDate;

No comments: