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

Trying to Make a XML field that displays DateTime in "TimeOnly" format but for some reason, I can't work it how to use it, as there isn't no "TimeOnly" property shown in Intellisense when i type the following code.

  <Field ID="{GUID id}"
    Name="CustomCalculatedTime"
    DisplayName="time"
    Group="cFields"
    Type ="DateTime"
    Format ="TimeOnly"
    Description=""
    ReadOnly="TRUE">
  </Field>

The error i get is

The "Format" attribute is invalid - The value 'TimeOnly' is invalid according to its datatype "http:/Schemas.microsoft.com/sharepoint/:DisplayFormat" - The Enumeration contraint failed.

share|improve this question
    
msdn.microsoft.com/en-us/library/aa979575.aspx Here it says we can use this property format, dunno whats wrong tho –  Muhammad Raja Mar 12 '12 at 12:03
add comment

3 Answers

up vote 1 down vote accepted

SharePoint stores Time information in Universal Time Code format (UTC) which means there is no way to store the time without the date. There are ways to configure the display of a column in things like a DataView Web part to only display the time. Or you could create a calculated column that will store a string representation of the just the time. But there is no way to store just the time.

For date/time fields, the Format values are possible: DateOnly - Display (and allow edits to) only the date portion (the time portion is set to 12:00 A.M. for all edited values). DateTime - Display and edit both date and time of day (default).

share|improve this answer
    
I looked at few places on Google to find the formula for calculated column field for "TimeOnly" but couldn't fine one, unless your asking me to save time in a textcolumn. cheers –  Muhammad Raja Mar 12 '12 at 13:09
add comment

The formula for time only is

TEXT([DateTimeField], "hh:mm:ss")
share|improve this answer
    
Cheers +1 for the post –  Muhammad Raja Mar 15 '12 at 9:21
add comment

You can add XSL-file to your list views for format of dates or using SPD. Under Miscellaneous there is an option to add a XSL link.

I'll give you an example, I'm not an expert on XSL, but the stylesheet under works. If its the best way to do it I don't know :)

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
    <xsl:include href="/_layouts/xsl/main.xsl"/>
    <xsl:include href="/_layouts/xsl/internal.xsl"/> 
    <xsl:template name="FieldRef_DateTime_body.DueDate" match="FieldRef[@Name='DueDate']"  mode="DateTime_body" ddwrt:dvt_mode="body">
        <xsl:param name="thisNode" select="."/>
            <xsl:value-of select="ddwrt:FormatDate(string($thisNode/@DueDate),1033,4)" />
    </xsl:template>
</xsl:stylesheet>

Note the format flag used is 4 for FormatDate, which means it takes out the Time Only, not the dates.

share|improve this answer
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.