Search code examples
xsltxslt-2.0xpath-2.0functx

Last day of previous month in XSLT


Is it possible to get the last day of the previous month in XSLT? I found this function: http://www.xsltfunctions.com/xsl/functx_last-day-of-month.html but I'm not sure how to use it to get the previous month.


Solution

  • Use:

    current-date()
      - xs:dayTimeDuration(concat('P', day-from-date(current-date()), 'D'))
    

    This produces (when evaluated on any day of May 2012):

      2012-04-30-07:00