Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting date difference in months

Keith B FosbergNov 4 2014 — edited Nov 4 2014

I need to get a date difference in number of months. This style sheet works but it returns number of days.

What do I need to do here to get months instead?

Given these inputs:

2014-11-04T11:32:28.256

2012-11-06T11:32:28.256

I get:

P698D

<?xml version="1.0" encoding="windows-1252" ?>

<xsl:stylesheet version="2.0"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"

    xmlns:ns0="http://www.example.org"

    xmlns:xsd="http://www.w3.org/2001/XMLSchema"

    exclude-result-prefixes="xsl ns0 xsd ora">

<?oracle-xsl-mapper

<mapSources>

<source type="XSD">

<schema location="input.xsd"/>

<rootElement name="input" namespace="http://www.example.org"/>

</source>

</mapSources>

<xsl:mapTargets>

<target type="XSD">

<schema location="output.xsd"/>

<rootElement name="output" namespace="http://www.example.org"/>

</target>

</mapTargets>

?>

<xsl:template match="/">

<ns0:output>

<ns0:duration>

<xsl:call-template name="monthDifference">

<xsl:with-param name="date1" select="/ns0:input/ns0:date1"/>

<xsl:with-param name="date2" select="/ns0:input/ns0:date2"/>

</xsl:call-template>

</ns0:duration>

</ns0:output>

</xsl:template>

<xsl:template name="monthDifference">

<xsl:param name="date1"/>

<xsl:param name="date2"/>

<xsl:value-of select="(xsd:dateTime($date1) - xsd:dateTime($date2))"/>

</xsl:template>

</xsl:stylesheet>

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2014
Added on Nov 4 2014
1 comment
331 views