0

I am trying to get the time value from the a DateTime field in SharePoint 2013 online.

When I try to retrieve the value of the field, it is showing only my browser time value. I am using the following code,

var ListItem;

function GetValue(){

   var SPContext = new SP.ClientContext(siteUrl);

   var list= SPContext.get_web().get_lists().getByTitle(listName);

   ListItem = list.getItemById(12345);

   SPContext.load(ListItem); 

   SPContext.executeQueryAsync(GetListItemById_Success, GetListItemById_Fail);
}

function GetListItemById_Success()
{

   var dateTimeValue = ListItem.get_item("DateTimeColumnName");

   alert(dateTimeValue);


}

Let me know how to get the stored DateTime Value. I'm unable to set the property set_datesInUtc(false).

1
  • see if these suggestion helps
    – cjs
    Commented Aug 22, 2017 at 16:58

1 Answer 1

0

Try this

function GetValue() {
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var web = '';
ctx = SP.ClientContext.get_current();
web = ctx.get_web();
var tsList = web.get_lists().getByTitle('YOURLISTNAMEHERE');
var tsQuery = new SP.CamlQuery()("<View><Query><Where><Eq><FieldRef 
Name='ID'/><Value Type='Text'>" + '12345' + "</Value></Eq></Where></Query>
</View>");
tsQuery.set_viewXml

ts = tsList.getItems(tsQuery);
ctx.load(ts);
ctx.executeQueryAsync(Success, Failed);
}

function Success() {
var tsE = ts.getEnumerator();
while (tsE.moveNext()) {
    var tsI = tsE.get_current();
    var tsCreated = tsI.get_item('DateTimeColumnName');

    var origDate = tsCreated.substr(0, tsCreated.indexOf('T'));
    var origTime = tsCreated.substring(tsCreated.lastIndexOf("T") + 1, 
tsCreated.lastIndexOf("Z"));
    alert(origDate);
    alert(origTime);
}

function Failed() {

alert("error");

}

}
1
  • Is this line of code correct, var tsQuery = new SP.CamlQuery()("<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + '12345' + "</Value></Eq></Where></Query> </View>"); tsQuery.set_viewXml
    – Selva
    Commented Aug 22, 2017 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.