How to show Friendly Date in SharePoint using Javascript or using Server side code



You can use following javascript code in order to show Date field value in Friendly format

var yourDate = new Date();

var friendlyDate = SP.DateTimeUtil.SPRelativeDateTime.getRelativeDateTimeString(yourDate , true, SP.DateTimeUtil.SPCalendarType.none, false)



Note that you need to add reference of “SP.dateTimeUtil.js” js in your page

<script type="text/javascript" src="/_layouts/15/SP.dateTimeUtil.js></script>

Following is the description about method argument:
1. Your date (Date ISO8601)
2. Specify whether want to include tiem or not(IncludeTime)
3. Calendar type (CalendarType)
4. Specify whether want to adjust time with server(AdjustToServersNowTime)

DateTime date = DateTime.Now;
string friendlyDate = SPRelativeDateTime.GetRelativeDateString(web, date.ToUniversalTime(), date); 

I Hope it will same someone’s time.