Knowledge Base Article

Home Page > Knowledge Base > Spira Platform

Home Page > Knowledge Base > Spira Platform > SpiraPlan

Home Page > Knowledge Base > Spira Platform > SpiraTeam

Home Page > Knowledge Base > Spira Platform > SpiraTest

Article How to Change the Date Format in the Spira Reports

by Adam S on Tuesday, January 6, 2015

To save space in the various SpiraTest, SpiraPlan and SpiraTeam reports, the default report templates use the format  xxxxx. Often times it will be required to display a different date format either across the entire report or in part of the report. This article describes how to change the date format in one of the standard reports by changing the XSLT template used to generate the report.

Modifying the Report

Log into your instance of SpiraTest, SpiraPlan or SpiraTeam. Then follow these steps:

  1. Go to Administration > System > Edit Reports
  2. Make a copy of the report you wish to change (e.g. Test Case Detailed)
  3. Click on the Edit button for the copy of this report
  4. On the report dialog box, click on the 'Customize' link for the appropriate section you wish to edit.
  5. This will display the edit section dialog box:
          
        
        
     
  6. Now cut and paste the contents of the 'Template' field into your favorite XML editor and you can modify the report and then save the updated report.

Changing the Template

Now that you have the XSLT template used to generate the report in an XML editor, you will see the following code used to format each of the dates:

<xsl:call-template name="format-date">
<xsl:with-param name="datetime" select="CreationDate" />
</xsl:call-template>

If you only want to change some of the dates in the report, you should change the name of the template that it is calling (e.g. format-date-expanded):

<xsl:call-template name="format-date-expanded">
<xsl:with-param name="datetime" select="CreationDate" />
</xsl:call-template>

If you want to change all of the dates in the report, you can leave this alone.

Next you need to modify the function (called a template in XSLT) that is responsible for actually formatting the date:

<xsl:template name="format-date">
<xsl:param name="datetime"/>
<xsl:variable name="date" select="substring-before($datetime, 'T')" />
<xsl:variable name="year" select="substring-before($date, '-')" />
<xsl:variable name="month" select="substring-before(substring-after($date, '-'), '-')" />
<xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
<xsl:variable name="time" select="substring-before(substring-after($datetime, 'T'), '.')" />
<xsl:variable name="monthname">
<xsl:choose>
<xsl:when test="$month='01'">
<xsl:value-of select="'Jan'"/>
</xsl:when>
<xsl:when test="$month='02'">
<xsl:value-of select="'Feb'"/>
</xsl:when>
<xsl:when test="$month='03'">
<xsl:value-of select="'Mar'"/>
</xsl:when>
<xsl:when test="$month='04'">
<xsl:value-of select="'Apr'"/>
</xsl:when>
<xsl:when test="$month='05'">
<xsl:value-of select="'May'"/>
</xsl:when>
<xsl:when test="$month='06'">
<xsl:value-of select="'Jun'"/>
</xsl:when>
<xsl:when test="$month='07'">
<xsl:value-of select="'Jul'"/>
</xsl:when>
<xsl:when test="$month='08'">
<xsl:value-of select="'Aug'"/>
</xsl:when>
<xsl:when test="$month='09'">
<xsl:value-of select="'Sep'"/>
</xsl:when>
<xsl:when test="$month='10'">
<xsl:value-of select="'Oct'"/>
</xsl:when>
<xsl:when test="$month='11'">
<xsl:value-of select="'Nov'"/>
</xsl:when>
<xsl:when test="$month='12'">
<xsl:value-of select="'Dec'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat($day, '-' ,$monthname, '-', $year , ' ', $time)" />
</xsl:template>

For example, we want to show that one date in an expanded format (e.g. ISO-8601 YYYY-MM-DD hh:mm). To do this we use the following function:

<xsl:template name="format-date-expanded">
<xsl:param name="datetime"/>
<xsl:variable name="date" select="substring-before($datetime, 'T')" />
<xsl:variable name="year" select="substring-before($date, '-')" />
<xsl:variable name="month" select="substring-before(substring-after($date, '-'), '-')" />
<xsl:variable name="day" select="substring-after(substring-after($date, '-'), '-')" />
<xsl:variable name="time" select="substring-before(substring-after($datetime, 'T'), '.')" />
<xsl:value-of select="concat($year, '-' ,$month, '-', $day , ' ', $time)" />
</xsl:template>

Attachments
Article Info
Last Updated: 1/6/2015
Article ID: KB104
# Views: 977
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.