Content by search web part server side version displays dates out by an hour

December 20, 2012

Since the release of SharePoint 2013 I have been lucky enough to use it in an actual project rather than playing around with it and I must admit there are several things which can be very frustrating. I came across a good example of one earlier today when doing some testing.

The project I am working on uses search to display news articles but since most of the search web parts all use JavaScript we also used the content by search web part set to run server side. Everything seemed to be working as expected until I noticed the dates on the JavaScript, figure 1, and non JavaScript version, figure 2, were different


Figure 1


Figure 2

The data being displayed is held in a list behind the screens and the field in question is a date only field. I double checked the date through the UI, figure 3, and I also wrote a PowerShell script, figures 4 & 5, but this confirmed the data was correct.


Figure 3


Figure 4


Figure 5

It just seemed like on the server side version it always removed an hour from the actual time so 20 June 2012 00:00:00 becomes 19 June 2012 23:00:00. I had a look around but I couldn’t see why it might be this and I looked on Google but I couldn’t see anything else on this.

In the implemented solution the list items being crawled via the search service were getting added via code so this allowed me to update the date field to set it to be 9am on the morning of the date entered. Even though the field type is date only it still stores the content in the DB with a time parameter so I could safely update this without fear of overwriting users content. This meant when the server side version removed an hour the value being returned is always 8am on the morning of the date entered, thus solving my problem.

I fully recognise there will be others who don’t have control over the content in the same manner so this solution will only work in certain circumstances. I would be very interested to see if anyone else has come across this and if so how they managed to resolve the issue.

%d bloggers like this: