Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I format this date

<xsl:value-of select="translate(@Created_x0020_Date,'0;#','')"></xsl:value-of>

to something like this UTC format - "2012-01-13T16:14:21Z"

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Probably you're looking for the ddwrt:FormatDateTime function:

FormatDateTime(string szDate, long lcid, string szFormat)

Internally, it wraps standard ASP.Net DateTime.ToString method, so for szFormat parameter you can use either Standard Data Format Strings or Custom Data Format Strings.

It seems that standard sortable format should do for you:

The "s" standard format specifier represents a custom date and time format string that is defined by the DateTimeFormatInfo.SortableDateTimePattern property. The pattern reflects a defined standard (ISO 8601), and the property is read-only. Therefore, it is always the same, regardless of the culture used or the format provider supplied. The custom format string is "yyyy'-'MM'-'dd'T'HH':'mm':'ss".

Thus, your code will look something like this:

<xsl:value-of select="ddwrt:FormatDateTime(translate(@Created_x0020_Date,'0;#',''), 1033, 's')" />

Then, you can append "Z" to the end of the resulting string (or you can just use custom format).

share|improve this answer
    
Thanks Omlin. "0211-12-02T14:47:03" But this is what i'm getting –  naijacoder Jan 16 '12 at 0:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.