How to format date in mvc web grid
If DateTime Property is defined as (can contain null) :
public DateTime? WorkedDate { get; set; }
Use this format:
grid.Column("WorkedDate", "Last Worked On",
format: (item) => item.WorkedDate != null
? item.WorkedDate.ToString("MM/dd/yy") : "", canSort: true)
Otherwise if it is defined as below (can't be null), it will have either actual date or .MinDate as the default.
public DateTime WorkedDate { get; set; }
Use format:
grid.Column("WorkedDate", "Last Worked On",
format: (item) => item.WorkedDate != DateTime.MinValue ?
item.WorkedDate.ToString("MM/dd/yy") : "", canSort: true)
grid.Column(
"PublishDate",
"Published on",
format: (item) => string.Format("{0:dd-MMM-yyyy}", item.PublishDate)
)