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

Free Support Forum - aspose.com

Mailmerge with DateTime fields... Locale doesn't seem to handle timezone conversions


I’m having a small issue with a user who has a simple field in a Word template. The field looks like:

{ MERGEFIELD Appointment_Time \@ "MMM d h:mm am/pm" }

The value of the Appointment_Time field is stored in GMT. The user would like the value of the field to appear as his local time zone, but it shows as the value of the timezone in which our server is located (which happens to be 3 timezones ahead of the location of the user).

This seems like a similar problem to formatting numerical values according to Locale settings, but since the Locale setting (“en-US”) doesn’t contain timezone, Words naturally uses the timezone of the server.

Do you have a suggestion on how I can get Words to use the current user’s timezone (which I do have available in my data) in evaluating date/time fields?


Thanks for your request. I have done some research and found the .NET source code that will help you to solve this problem. See the following link.
Best regards.

Many thanks, Vitaly. I really appreciate you looking for this for me.

In my case, I was hoping for a solution within Aspose.Words because the data set I’m working with is different for each of my users, so I don’t have the luxury of knowing which fields are date-time fields and which are not. So I won’t be able to programmatically convert values to the correct timezone using typical tools.

However, perhaps I can use a merge field event handler to determine if the user has applied a Date/Time picture switch to the field, and if so, attempt to convert it to their timezone, and then use Words to insert the value.

Hmmm… that sounds like it might work.

Thanks again for the direction on this.


Thanks for your request. You can try to use MergeField event to convert Date During Mail Merege. See the following code example.

public void TestConvertData_97574()
    Document doc = new Document(@"246_97574_DenverMike\in.doc");
    string[] names = { "Appointment_Time" };
    object[] values = { DateTime.Now };
    doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_97574);
    doc.MailMerge.Execute(names, values);
void MailMerge_MergeField_97574(object sender, MergeFieldEventArgs e)
    if (e.Field.GetFieldCode().Contains("MMM d h:mm am/pm"))
        // here you should convert date
        e.Text = "12.12.2007";

Best regards.