Header filter date format

Hi all,

does anybody know a way to set date format for dataview header filter? Here is a screenshot of what I have now:

As you can see, the format is dd.mm.yyyy h:nn. I want to remove the time part and to have dd.mm.yyyy only. It is a common XSLT Data View. The header for this field is:

<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
    <xsl:with-param name="fieldname">@Error_x0020_date</xsl:with-param>
    <xsl:with-param name="fieldtitle"> </xsl:with-param>
    <xsl:with-param name="displayname">Error date</xsl:with-param>
    <xsl:with-param name="sortable">1</xsl:with-param>
    <xsl:with-param name="fieldtype">x:dateTime</xsl:with-param>
</xsl:call-template>

And the field itself is:

<td class="ms-vb">
    <xsl:value-of select="ddwrt:FormatDate(string(@Error_x0020_date), 1049, 1)"/>
</td>

So in the field I can see the date in the way I want:

But where should I set up date format for the header like I do for the field itself?

Thanks in advance!

November 23rd, 2011 8:27am

You could always use a computed column field; set the Error_Date field to your computed column field, use data calculations to format the date to meet your requirements and choose the "Single line text" options to return your data as a string. Then finally include your new computed column into your target view and you should be set to go.

Intro to data calculations: http://office.microsoft.com/en-us/windows-sharepoint-services-help/introduction-to-data-calculations-HA010121588.aspx

Free Windows Admin Tool Kit Click here and download it now
November 24th, 2011 2:55am

Hi Brandon,

why should I use a computed column when I already have a proper date format in the field? The problem in the filter values. I don't understand why there is "h:nn" part and where it can be changed.

November 24th, 2011 6:26am

Andrey,

Can you try this?  http://www.stylusstudio.com/xsllist/200010/post90330.html

 

Cheers,

Jeff - MSFT

Free Windows Admin Tool Kit Click here and download it now
November 29th, 2011 12:33am

Hi Jeff,

thanks for your reply. Maybe I misunderstand smth, but I can't see any reply in the thread your link goes to.

November 29th, 2011 6:00am

Hi Andrey,

My mistake.  I posted the wrong link earlier.  But I have also found that I misunderstood your question.  I just tried what you described in a new DataSheet view on one of my lists and the filter is formatted without the time.  I wondered if this is something specific to the Russian language pack?

Free Windows Admin Tool Kit Click here and download it now
November 29th, 2011 11:23pm

Hi Jeff,

I don't think there is Russian language pack influence. The only difference is that we use dd.mm.yyyy date format as a default one rather than mm.dd.yyyy or mm/dd/yyyy and 24 hours time format.

If we are talking about a common "Created" SharePoint field, it shows filter values ok in a standard Sharepoint list:

I can't try with a brand new XSLT DataView right now because I have some temporary troubles with SPD, but I'll try it ASAP after repairing and let you know whether the issue still appears.

December 1st, 2011 11:42am

I  had the same problem with filter. If I return date type from database, I get time stamp in the filter. If I format it to string using convert function, sort didn't work as it supposed to work with date, instead, it was sorting like string. So my solution was to have date format for sorting and string format for filter.

 The work around I did to get rid of time stamp in the filter is below.

In the data source, in addition to date field, I also added another field with date format.

Eg. DueDate is my date field which return date type, I added another field called FormattedDueDate which will return string type as shown below.

CONVERT(VARCHAR(10), A.DueDate, 101) AS FormattedDueDate, A.DueDate

In designer, I added this FormattedDueDate to the data source. In the header field, I have added another parameter name called "sortfieldname". So my source code change is

orignal code:

<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
       <xsl:with-param name="fieldname">@DueDate</xsl:with-param>
           <xsl:with-param name="fieldtitle">Due Date</xsl:with-param>
       <xsl:with-param name="displayname">Due Date</xsl:with-param>
       <xsl:with-param name="sortable">1</xsl:with-param>
       <xsl:with-param name="fieldtype">x:string</xsl:with-param>
      </xsl:call-template>

Updated code:

<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
       <xsl:with-param name="fieldname">@FormattedDueDate</xsl:with-param>
       <xsl:with-param name="sortfieldname">@DueDate</xsl:with-param>
       <xsl:with-param name="fieldtitle">Due Date</xsl:with-param>
       <xsl:with-param name="displayname">Due Date</xsl:with-param>
       <xsl:with-param name="sortable">1</xsl:with-param>
       <xsl:with-param name="fieldtype">x:string</xsl:with-param>
      </xsl:call-template>

Now I will have to use the new sortfieldname variable in the sort functionality. For this I added sortfieldname in the param list and replaced "fieldname" with "sortfieldname" in the sortfield choose block.

Orignal code:

<xsl:template name="dvt.headerfield">
       <xsl:param name="fieldname" />
       <xsl:param name="fieldtitle" />
       <xsl:param name="displayname" />
       <xsl:param name="sortable">1</xsl:param>
       <xsl:param name="fieldtype">0</xsl:param>
       <xsl:choose>
        <xsl:when test="($dvt_adhocmode = 'sort' or $dvt_fieldsort = '1')and $sortable='1'">
         <xsl:variable name="sortfield">
          <xsl:choose>
           <xsl:when test="substring($fieldname, string-length($fieldname) - 5) = '(text)'">
       <xsl:value-of select="substring($fieldname, 1, string-length($fieldname) - 6)" />
      </xsl:when>
           <xsl:when test="substring($fieldname, 1, 1) = '@'">
       <xsl:value-of select="substring($fieldname, 2)" />
      </xsl:when>
           <xsl:otherwise>
       <xsl:value-of select="$fieldname" />
      </xsl:otherwise>
          </xsl:choose>
         </xsl:variable>

Modified code:

<xsl:template name="dvt.headerfield">
  <xsl:param name="fieldname" />
  <xsl:param name="sortfieldname" />
  <xsl:param name="fieldtitle" />
  <xsl:param name="displayname" />
  <xsl:param name="sortable">1</xsl:param>
  <xsl:param name="fieldtype">0</xsl:param>
  <xsl:choose>
   <xsl:when test="($dvt_adhocmode = 'sort' or $dvt_fieldsort = '1')and $sortable='1'">
    <xsl:variable name="sortfield">
     <xsl:choose>
      <xsl:when test="substring($sortfieldname, string-length($sortfieldname) - 5) = '(text)'">
       <xsl:value-of select="substring($sortfieldname, 1, string-length($sortfieldname) - 6)" />
      </xsl:when>
      <xsl:when test="substring($sortfieldname, 1, 1) = '@'">
       <xsl:value-of select="substring($sortfieldname, 2)" />
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="$sortfieldname" />
      </xsl:otherwise>
     </xsl:choose>
    </xsl:variable>

Now I see old date without time in the filter and I also able to sort the field as date.

Thanks

Mahi

Free Windows Admin Tool Kit Click here and download it now
May 13th, 2015 6:09pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics