Date issue : we want to decrease month value from date

Hi Team, We are using aspose word java 24.1 linq engine. Our requirement is we are getting date in json : “dataSourcingDate”: “2024-07-31” where we need a aspose linq engine syntax to reduce month from received date and that should give proper lastday and year of that given date.
for example : “dataSourcingDate”: “2024-07-31” (-1 month)
result date : 2024-06-30

@anupkrsinha There is no such syntax. But you can define an util method to get the required date. For example:

import java.util.Date;

public class MyUtil {
    public static Date GetMonthLastDate(Date d) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }
}

Then you can use this util method in your template:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("<<[MyUtil.GetMonthLastDate(lastMonthendDate)]>>");
        
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(MyUtil.class);
engine.buildReport(doc, new Date(), "lastMonthendDate");

doc.save("C:\\Temp\\out.docx");

See our documentation for more information:
https://docs.aspose.com/words/java/setting-up-known-external-types/