Please help me with the code of converting given calendar date to Julian date(YYYYMMM) 7 bytes format using xslt please...
Thanks in advance !
Please help me with the code of converting given calendar date to Julian date(YYYYMMM) 7 bytes format using xslt please...
Thanks in advance !
The JD Edwards date format (which is often referred to incorrectly as the JDE Julian Date format) is a CYYDDD
format, where:
C
is a number denoting the century: a value of 0 represents years between 1900 and 1999, a value of 1 years from 2000 to 2099, and so on;YY
denotes the year in the given century;DDD
is the day number in the given year.Thus, for example, the date of 2019-07-02
would be represented as 119183
.
To convert a date in YYYY-MM-DD
format to JD Edwards date format using XSLT 1.0, you can use:
<xsl:template name="date-to-JDE">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="C" select="floor($year div 100) - 19"/>
<xsl:variable name="YY" select="$year mod 100"/>
<xsl:variable name="leap" select="not($year mod 4) and $year mod 100 or not($year mod 400)" />
<xsl:variable name="elapsed-months" select="substring('000031059090120151181212243273304334', 3 * ($month - 1) + 1, 3)"/>
<xsl:variable name="DDD" select="$elapsed-months + ($month > 2 and $leap) + $day"/>
<xsl:value-of select="$C * 100000 + $YY * 1000 + $DDD"/>
</xsl:template>
Demo: https://xsltfiddle.liberty-development.net/jyRYYj8
If you actually need YYYYDDD, then you can simplify the above to:
<xsl:template name="date-to-YYYYDDD">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="leap" select="not($year mod 4) and $year mod 100 or not($year mod 400)" />
<xsl:variable name="elapsed-months" select="substring('000031059090120151181212243273304334', 3 * ($month - 1) + 1, 3)"/>
<xsl:variable name="DDD" select="$elapsed-months + ($month > 2 and $leap) + $day"/>
<xsl:value-of select="$year * 1000 + $DDD"/>
</xsl:template>
In XSLT 2.0, format-date() with picture [Y0001][d001]
should give you what you want.
If you can't use XSLT 2.0, see whether your XSLT processor supports the date/time extensions defined at www.exslt.org