We're sorry Aspose doesn't work properply without JavaScript enabled.

# Define the date and time that is used for field updates

In one of my integration tests I would like to test the automatic update of fields, for example the current date in a document.

By default, Aspose.Words apparently uses the current system date/time to update fields.
For my integration test, I would like to overwrite the date and time since I would like to test the date formatting for specific months.

Is there a way to overwrite the date and time that Aspose.Words uses to update fields?

@bwaldvogel I think in your case, for testing purposes, you can simply use some different type of fields wit date switches. For example you can try using merge fields with date formatting switches. For example see the input and output documents and the following test code:

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.Execute(new string[] { "date1", "date2", "date3" },
new object[] { new DateTime(2022, 2, 24), new DateTime(2021, 5, 3), new DateTime(2020, 1, 1) });
doc.Save(@"C:\Temp\out.docx");


in.docx (12.2 KB) out.docx (9.5 KB)

@alexey.noskov: Thanks for your reply. If I understood it correctly, this would require me to have a field of type “FieldMerge” in my input document. However, I do not want to change the input document for testing since I wouldn’t test the actual document anymore.

Isn’t there a way to tell Aspose.Words to use a specific date/time when updating the fields?
Is this maybe something that could be added to CurrentThreadSettings?

@bwaldvogel Unfortunately, there is no way to specify the current date and time of field updating engine. It uses the current time. That is why I have suggested you to use another type of fields, which can accept date time value to test field formatting.