1

Using KeywordQuery to query for a field that is DateTime, code sample below (on-premises SharePoint 2013 farm):

var kq = new KeywordQuery(_site)
q.SelectProperties.Add("OurDateTimeField");
SearchExecutor se = new SearchExecutor();
var rt = se.ExecuteQuery(kq);
ResultTable rtt = rt[ResultType.RelevantResults];

foreach (DataRow rr in rtt.ResultRows)
{
string mydate = rr["OurDateTimeField"]; 
}

OurDateTimeField is a DateTime-type managed property that is mapped to a DateTime-type User Property in UPS. Thing is, it's returned as "string" type by KQ.

Problem: returned string is actually an initial DateTime value (sitting in user's property) converted to a string by server using some arbitrary datetime format. It does not always match datetime format used by CurrentCulture, CurrentUICulture, sharepoint web's culture, or default culture of every possible relevant service account (we tried farm account, MySite host's app pool account, search service's account, web's app pool account etc).

This is a problem because we have to convert this string back to DateTime type, and to do so we need to know formatting pattern that was used (try to convert "25.04.2017" using pattern from en-US culture or "invariant" culture).

Is there a way to find out which format pattern was used?

0 Answers0