3

I am working on an on-premises farm 2013. and i have added a Search Result web part, which should show documents from multiple documents libraries. now one of the properties i am showing inside the Search Result Web Part named LastModifiedTime, as follow:-

<mso:ManagedPropertyMapping msdt:dt="string">'ListID','ListItemID','ContentTypeId','FileType','Link URL':'Path','CommentOWSMTXT','BodyOWSMTXT','Property 1':'FileName','Property 2':''*****','Property 7':'LastModifiedTime','Property 8':'EditorOWSUSER','SecondaryFileExtension'</mso:ManagedPropertyMapping>

now i have noted a problem that the LastModifiedTime managed property will not get updated when i edit a word document properties. for example i have the following document which have its modified date = 37 minutes ago inside the actual document library:-

enter image description here

while inside the Search Result web part the LastModifiedTime will be equal to 5 September:-

enter image description here

now for example i click on the document property using the system account and i change one of the document property, where the modifiedBy inside the Search Result web part will be updated but the LastModifiedTime will still be 5 sep.. so users will be confused they will think that the system account have updated the document on 5 Sep, while it was modfied 37 minutes ago ..so not sure what is the problem. keeping in mind that i have uploaded a .png image, where i edit its properties and both the LastModifiedTime & modifed by were updated inside the Search Result web part.. but seems this is problem is happening to word documents and pdf.. did not test for other types..

  • 1
    can you map ows_Modified crawled property to a RefinableDatexx managed property and check ? – Gautam Sheth Sep 18 '17 at 11:45
  • @GautamSheth thanks now i mapped the RefinableDate00 with ows_Modified then i modify my search result web part to start showing the RefinableDate00 .. now the actual last modified date for the document is 15/09/2017 16:24 when viewing the document inside the view form.. but inside the search result web part i got this value 15/09/2017 15:24:00 so i am not sure why i got 15 instead of 16 for the hour part, and when i try to remove the seconds using this code – john Gu Sep 18 '17 at 23:52
  • if (property.managedPropertyName === 'RefinableDate00') { var modifiedDate2 = new Date((ctx.CurrentItem.RefinableDate00)); modifiedDate2 = modifiedDate2.format("dd/MM/yyyy hh:mm"); _#--> _#= modifiedDate2 =#_ <!--#_ } i got the date on march 2018 !!.. so not sure how i can remove the seconds and have the hour equal to 16 instead of 15?? for the RefinableDate00 managed property ? – john Gu Sep 18 '17 at 23:53
2
+25

LastModifiedTime managed property does not always show the modified date value of a list item. The reason behind that is that LastModifiedTime managed propery is mapped to multiple crawled properties as below:

enter image description here

Since its SharePoint, there are multiple timer jobs running internally in the background which affect the modified date values of SharePoint sites, lists, list item etc.

Now you have 2 options:

1) You can re-order these crawled properties and move ows_Modified to the top. After that wait for the full crawl and it will get the modified date/time values. However, I wouldn't recommend it as we would be modifying the OOTB managed property. There is no harm in doing this though.

2) To always get the modified value of a list item only, you should map the ows_Modified crawled property to a managed property like RefinableDateXX. This will always ensure that you get the Modified date time values of a list item. I would recommend using this approach as it doesn't modify the OOTB managed property and would be easier in case of migration.

Now, you mentioned that the value is 1 hour behind, not really sure why its like, it could be due to multiple reasons like daylight savings or Regional settings at the site collection or web application level or some other reason. However, you can try the below work around in your display template.

if (property.managedPropertyName === 'RefinableDate00'){

    var modifiedDate2 = ctx.CurrentItem.RefinableDate00;
    if(modifiedDate2){
        modifiedDate2 = new Date(ctx.CurrentItem.RefinableDate00);
        //set the date time value to 1 hour behind
        modifiedDate2.setHours(modifiedDate2.getHours()-1);
        var formattedDate = String.format("{0:dd}/{0:MM}/{0:yyyy} {0:t}",modifiedDate2);
        console.log(formattedDate);
    }

}

In your html, you can use it as below:

_#= formattedDate =#_

Edit 2 - Not sure why the above didnt work, it worked for me in SP Online. However, i tried the below 2nd approach and it work.

var modifiedDate2 = $getItemValue(ctx, 'RefinableDate00'); 
if(modifiedDate2.value){                        
    var parseDate = new Date(modifiedDate2.value);

    var formattedDate = parseDate.format('dd-MM-yyyy hh:mm');                        
}

References -

Changing date format using javascript

Search returns wrong date (date -1)

SharePoint stores dates in UTC time

  • now formatting the ctx.CurrentItem.RefinableDate00 in the way you are doing it have produced date in 2018.. so instead of getting 19/09/2017 11:41 i got 09/07/2018 09:51 !! not sure what is going on.. – john Gu Sep 19 '17 at 11:36
  • whats the full value in RefinableDate00 ? At my end i get something like 15/09/2017 15:24:00 PM for a value. Also, please check the edited code. – Gautam Sheth Sep 19 '17 at 12:14
  • now if i am showing the ctx.CurrentItem.RefinableDate00 as is without any formatting i will get value such as 19/09/2017 11:38:54 which is the correct time except that i have one hour behind(which is not a big deal at this stage).. but using your format the value will be 07/09/2018 10:38 – john Gu Sep 19 '17 at 12:16
  • hmm quite strange, can you try it as var modifiedDate2 = $getItemValue(ctx, 'RefinableDate00'); var formattedDate = modifiedDate2.value.format('dd-MM-yyyy hh:mm'); ? – Gautam Sheth Sep 19 '17 at 12:27
  • but this will raise the following error Object doesn't support property or method 'format' – john Gu Sep 19 '17 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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