Reading JavaScript date values from SharePoint date fields regardless of locale (culture)

Document created by AdisJ Employee on Apr 11, 2018Last modified by AdisJ Employee on Apr 11, 2018
Version 3Show Document
  • View in full screen mode

Using standard JavaScript Date.parse() method with JavaScript does not really work with SharePoint fields, since it does not take in account the locales of the SharePoint site. 

In order to do that properly from skybow Solution Studio (regardless if Rich Forms or Action Links), the easiest is to use moment.js JS library.

 

// load the moment.js library
var url = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js";
var fileName = "momentjs";
var moduleCache = window.module;
var defineCache = window.define;
window.module = undefined;
window.define = undefined;
window.SP.SOD.registerSod(fileName, url);
window.LoadSodByKey(fileName, null, true);
window.module = moduleCache;
window.define = defineCache;

//parse date by moment.js and get an integer representation
var dateInt = Date.parse(moment([[datefield]]));

//create a date object out of it
var dateObject = new Date(dateInt);

Attachments

    Outcomes