Modify the date format for a search result items inside the callouts in a ent.search site . currently we are having the SP default date format , like mm/dd/yyyy, i need to change it to a format like 23-Mar-2017 , ie dd-mmm-YYYY. How to achieve this?


2 Answers 2


We need to updated the date format in the display Tempaltes.

Copy/paste a variable in the template, something like:

var modifiedDate =  $getItemValue(ctx, "ModifiedOWSDATE");
And use that variable instead:

<p>_#= modifiedDate =#_</p>
If creating a new custom Value Renderer etc is not an option for formatting the date (The default pattern used by Search.ClientControls isLongDatePattern I think). One could always create a Date variable, and do as fit:


<p>_#= new Date(modifiedDate["inputValue"]).toLocaleString() =#_</p>

please check the sharepoint.stackexchange post Changing date format in display templates for SharePoint 2013

It may help you..


Instead of creating Dateformat yourself or loading moment.js...

SharePoint adds a String.format function
so you can use:

String.format('{0:yyyy}-{0:MM}-{0:dd}',new Date('2015-10-30T05:00:00Z'));

Note: String.format is defined in msajaxbundle.js, loaded even before most of the JavaScript files so safe to use without SOD requirements or anything.
It was modelled after the C# and VB implementations, so the MSDN documentation applies
(for the major part; it does not do the alignment stuff as that makes no sense in HTML)

MSDN String.format() Documentation

String.format("{0:i}",new Date());  outputs: Wed Oct 07 2015 20:39:54 GMT+0200 (W. Europe Daylight Time)
String.format("{0:F}",new Date());  outputs: Wednesday, 07 October 2015 20:39:54
String.format("{0:f}",new Date());  outputs: Wednesday, 07 October 2015 20:39
String.format("{0:D}",new Date());  outputs: Wednesday, 07 October 2015
String.format("{0:s}",new Date());  outputs: 2015-10-07T20:39:54
String.format("{0:d}",new Date());  outputs: 10/07/2015
String.format("{0:dd}",new Date());  outputs: 07
String.format("{0:ddd}",new Date());  outputs: Wed
String.format("{0:dddd}",new Date());  outputs: Wednesday
String.format("{0:m}",new Date());  outputs: October 07
String.format("{0:M}",new Date());  outputs: October 07
String.format("{0:MM}",new Date());  outputs: 10
String.format("{0:MMM}",new Date());  outputs: Oct
String.format("{0:MMMM}",new Date());  outputs: October
String.format("{0:Y}",new Date());  outputs: 2015 October
String.format("{0:y}",new Date());  outputs: 2015 October
String.format("{0:yy}",new Date());  outputs: 15
String.format("{0:yyyy}",new Date());  outputs: 2015
String.format("{0:gg}",new Date());  outputs: A.D.
String.format("{0:T}",new Date());  outputs: 20:39:54
String.format("{0:t}",new Date());  outputs: 20:39
String.format("{0:HH}",new Date());  outputs: 20
String.format("{0:mm}",new Date());  outputs: 39
String.format("{0:ss}",new Date());  outputs: 54

J5 iJS string format top20

  • Danny, where will I update the code string.format() ? if you please can elaborate a little bit.... Mar 23, 2017 at 14:08
  • In the Search DisplayTemplate the other answer pointed you to Mar 23, 2017 at 16:59
  • {0:yyyy-MM-dd} should also work Jan 30, 2018 at 11:08

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.