 <p>I did some of your work for you and found <a href="http://www.exslt.org/date/functions/duration/index.html">this date:duration function</a>, which you seem to be trying to use. However, date:duration converts a number of seconds into a duration formatted string, whereas you want to find the difference (duration) between two datetime strings.</p> <p>You probably want <a href="http://www.exslt.org/date/functions/difference/date.difference.template.xsl">date:difference</a> instead. If you read the <a href="http://www.exslt.org/date/functions/difference/index.html">documentation for this function/template</a>, you'll find this about the arguments:</p> <blockquote> <p>The two dates must both be right-truncated date/time strings in one of the formats defined in [XML Schema Part 2: Datatypes]. ... The permitted formats are as follows...</p> <pre><code>xs:dateTime (CCYY-MM-DDThh:mm:ss) ... </code></pre> </blockquote> <p>There are italics there in the original: <em>CCYY-MM-DDThh:mm:ss</em> except the T is not italicized. In other words, the time strings need a literal <code>T</code> between the date and the time, whereas yours have a space.</p> <p>So I would suggest fixing that:</p> <pre><code>&lt;start&gt;2011-12-13T16:15:26&lt;/start&gt; &lt;end&gt;2011-12-13T16:17:27&lt;/end&gt; </code></pre> <p>Pass the <code>start</code> and <code>end</code> strings as parameters to the template. You can do this by just passing the <code>start</code> and <code>end</code> element nodes, which will be automatically converted to strings based on their text content:</p> <pre><code>&lt;xsl:variable name="time-diff-dur"&gt; &lt;xsl:call-template name="date:difference"&gt; &lt;xsl:with-param name="start" select="start" /&gt; &lt;xsl:with-param name="end" select="end" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; &lt;!-- The above returns a duration formatted string, so convert that to seconds: --&gt; &lt;xsl:variable name="time-diff-sec"&gt; &lt;xsl:call-template name="date:seconds"&gt; &lt;xsl:with-param name="seconds" select="$time-diff-dur" /&gt;? &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; </code></pre> <p>This code assumes that the context node is the parent of the <code>&lt;start&gt;</code> and <code>&lt;end&gt;</code> elements. After the above code, the variable <code>$time-diff-sec</code> will contain a result tree fragment, which can be converted to a number using <code>number($time-diff-sec)</code> if necessary.</p> <p>Let us know whether that works. If not, state specifically <strong>what the result was</strong> and how it differs from what you expected.</p> <p><strong>Update:</strong></p> <p>I just noticed that you are using xsltproc (which uses libxslt). According to <a href="http://www.exslt.org/date/functions/difference/index.html">this documentation</a>, libxslt supports <code>date:difference</code> (and <code>date:seconds</code>) natively. So you can call these functions as functions instead of defining a named template and calling it as a template. That would be a lot less code for you, albeit less portable:</p> <pre><code>&lt;xsl:variable name="time-diff-sec" select="date:seconds(date:difference(start, end))" /&gt; </code></pre> <p>As before, you will need to declare the <code>date</code> namespace prefix somewhere, usually on your <code>xsl:stylesheet</code> element:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date"&gt; </code></pre>