Tuesday, February 2, 2010

Get Month from a DateTime Field in Sitecore

Using sc:formatdate(), is a sweet and simple method to format a date in a Sitecore rendering. 

For Example:
sc:formatdate(sc:fld('MyDateField', .),'d MMM yyyy @ h:mm')

Using the format string 'MMM' gives us the three-letter month names, while the 'MM' gives months in the numeric format (eg. 02 for Feb), and 'M' gives us the  full month name along with the date.

Another way is using the substring-after in conjunction with the format '/M'. 

For Example:
substring-after(sc:formatdate(sc:fld('MyDateField', .), '/M'), '/')