locked
Removing "TIME" with IncludeTimeValue="FALSE" RRS feed

  • Question

  • Hi everyone.

    I have a date & time field stored on MS SQL server which stores the date as: 5/31/2011 11:32 AM BUT i want to REMOVE the Time part so it only shows the Date eg. 5/31/2011.

    I opened the page in Sharepoint Designer and I am able to see the field listed:
    <B><FieldRef Name="Project_x0020_End_x0020_Date"/></b>

    I tried using the <b>IncludeTimeValue="FALSE"</b> but when I tried saving the file it crashes.

    How can I get it to DISPLAY only the Time? Below is the call the code from the list.aspx file.

    <B>

    <XmlDefinition>
                <View Name="{61A12915-C416-4B7A-994C-B3743xsfr}" MobileView="TRUE" Type="HTML" DisplayName="ProjectFile" Url="/Projects/devryschool/project/Lists/ProjectDevry/ProjectFile.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png">
                    <Method Name="Read List"/>
                    <Query/>
                    <ViewFields>
                        <FieldRef Name="_x0043_"/>
                        <FieldRef Name="My_x0020_End_x0020_Date"/>
                    </ViewFields>
                    <RowLimit Paged="TRUE">30</RowLimit>
                    <Aggregations Value="Off"/>
                    <Toolbar Type="Standard"/>
                </View>
            </XmlDefinition>
    </B>

    Thank you.


    C


    nothing for members to see
    • Moved by Mike Walsh FIN Thursday, February 17, 2011 9:02 AM SPD so customization not programming (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Wednesday, February 16, 2011 9:01 PM

Answers

  • Hi,

    If the column is not built-in column, you can change the format of it to display date only from the the following settings: Library Setting=>click the target column=>select the 'date only' in the Additional Column Settings.

    If it was, you can try the following code.

     
     SPFieldDateTime field = yourlist.Fields["yourname"] as SPFieldDateTime;
          field.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
          field.Update();
    

    Microsoft Online Community Support
    • Marked as answer by KeFang Chen Thursday, February 24, 2011 8:19 AM
    Thursday, February 17, 2011 6:31 AM

All replies

  • Hi,

    If the column is not built-in column, you can change the format of it to display date only from the the following settings: Library Setting=>click the target column=>select the 'date only' in the Additional Column Settings.

    If it was, you can try the following code.

     
     SPFieldDateTime field = yourlist.Fields["yourname"] as SPFieldDateTime;
          field.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
          field.Update();
    

    Microsoft Online Community Support
    • Marked as answer by KeFang Chen Thursday, February 24, 2011 8:19 AM
    Thursday, February 17, 2011 6:31 AM
  • In relation to the code below, where do I place your code? Sharepoint automatically generated the code below. I don't think I understand your suggestion. Sorry this stuff is new to me.

     

    <XmlDefinition>
          <View Name="{61A12915-C416-4B7A-994C-B3743xsfr}" MobileView="TRUE" Type="HTML" DisplayName="ProjectFile" Url="/Projects/devryschool/project/Lists/ProjectDevry/ProjectFile.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png">
            <Method Name="Read List"/>
            <Query/>
            <ViewFields>
              <FieldRef Name="_x0043_"/>
              <FieldRef Name="My_x0020_End_x0020_Date"/>
            </ViewFields>
            <RowLimit Paged="TRUE">30</RowLimit>
            <Aggregations Value="Off"/>
            <Toolbar Type="Standard"/>
          </View>
        </XmlDefinition>

     


    nothing for members to see
    Thursday, February 17, 2011 2:30 PM
  • Hi cecilita, is this a part of a XSLT ListViewWebPart in SP2010? In order to change something for the FieldRefs you can create a XSL stylesheet to transform what you want. When you need to change the way the Date render you can use format flags, 1 = 2/18/11. Try something like this below the ending tag </XmlDefinition>

    / Christian

    <xsl>
    <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:param name="AllRows" select="/dsQueryResponse/Rows/Row[$EntityName = '' or (position() &gt;= $FirstRow and position() &lt;= $LastRow)]"/>
     	<xsl:param name="dvt_apos">'</xsl:param>
    	<xsl:template name="FieldRef_ValueOf.My_x0020_End_x0020_Date" ddwrt:dvt_mode="body" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
      	<xsl:param name="thisNode" select="."/>
      	<xsl:variable name="ID">
    			<xsl:call-template name="ResolveId">
    				<xsl:with-param name="thisNode" select="$thisNode" />
    			</xsl:call-template>
    		</xsl:variable>
    			<xsl:value-of select="ddwrt:FormatDate(string($thisNode/@My_x0020_End_x0020_Date), 1033, 1)"/>
     </xsl:template>
     </xsl:stylesheet>
    </xsl>
    
    

    Blog: chrisstahl.wordpress.com Twitter: @Cstahl
    Thursday, February 17, 2011 6:40 PM
  • Hi,

    My code above needs to create a console application to be ran.


    Microsoft Online Community Support
    Friday, February 18, 2011 2:16 AM