I have current xslt xp20:format-dateTime(string(fn:current-dateTime ()), "[Mn,*-3]-[Y01]")
to retrieve current month in mmm-yy format but I am not able to subtract a month. I would imagine it would look something along the lines of xp20:format-dateTime(string(fn:current-dateTime ()), "[Mn,*-3]-[Y01]") - xsd:dayTimeDuration('P1M')), '[Mn,*-3]-[Y01]')
Asked
Active
Viewed 134 times
1

joelouis
- 31
- 3
-
1Which XSLT processor is this for? – michael.hor257k Jan 12 '23 at 18:28
-
I am using Oracle Integration Cloud Service so I am not sure which XSLT processing they use. – joelouis Jan 13 '23 at 19:59
-
It seems to be an XSLT 1.0 processor that supports some extension functions from the XSLT 2.0 set. You can verify this as shown [here](https://stackoverflow.com/a/25245033/3016153). If you cannot make the XSLT 2.0 solution below work, I'll add another that uses only XSLT 1.0 (provided you have a way to get the current date, which apparently you do). – michael.hor257k Jan 13 '23 at 20:52
-
Note also that if you don't have a way to subtract a yearMonthDuration, you can extract the day and use it to subtract a dayTimeDuration with the same value. This will return the last day of the previous month - and you can format it the way you want. – michael.hor257k Jan 13 '23 at 21:00
2 Answers
1
In XSLT 2.0 or higher you can subtract one month from the current date using:
current-date() - xs:yearMonthDuration('P1M')
then format the resulting date the way you want it.
For example, the instruction:
<xsl:value-of select="format-date(current-date() - xs:yearMonthDuration('P1M'), '[Mn,*-3]-[Y01]')" />
will return:
dec-22
if performed on any day of January 2023.

michael.hor257k
- 113,275
- 6
- 33
- 51
0
In Oracle Integration Cloud the below returned previous month and year in Mmm-YY.
`xp20:format-dateTime(string(xsd:dateTime(fn:current-dateTime()-xsd:yearMonthDuration('P1M'))),"[Mn,*-3]-[Y01]")`
Ran in Jan 2023 returned Dec-22

joelouis
- 31
- 3