Search code examples
datexsltdate-format

xslt for a date 90 days older than current date


I have used the following to get the current date.

<value><xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('dd-MM-yyyy'), java:java.util.Date.new())"/></value>

Now, I have a requirement where I have to get a date that is not older than 90 days from today. Please help me out to get it done using xslt?


Solution

  • Hey Thanks all for your responses. I have solved this issue using below code.

    <xsl:value-of select="java:com.Utilities.getDeletedDate()" />
    

    In the Utilities class i have added one method as follows.

    public static String getDeletedDate() {
    
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, -99);
        Date date = cal.getTime();
        DateFormat secondFormatter;
        String formatedDate = null;
        secondFormatter = new SimpleDateFormat("yyyy-MM-dd");
        formatedDate = secondFormatter.format(date);
        return formatedDate;
    }
    

    This is working fine for me.