Format Date

One of the things I find myself looking up frequently is Date Values for SharePoint. When creating custom display forms, you typically end up with date and time values that look something like this: 2013-07-24T21:00:00Z. This isn’t really a useful value (to an end user). To change it to something more readable open designer and the disp form:

Find the date field:

My Start Time field looks like this in the form:
The corresponding code in designer:
The xsl:value of tag contains the information to modify. The select attribute is equal to the EventDate value, which is the Start Time. To make a more readable value, it can be changed to:
The ddwrt namespace must be included to use a function like FormatDate. FormatDate, like the name implies, will change the formatting shown above to something useful or readable to an end user. Explanation of the parameters taken from the msdn page:
“The parameter szDate is converted to a DateTime. Based on the formatFlag parameter, which can have a value 0–15, a new DateTime string is constructed in the given locale lcid. Table 5 shows the results returned from this function.”
The above code will result in the below; a nicely formatted date for end users:
Check the msdn article for a list of formats.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s