Free Support Forum -

ExecuteWithRegions and Date Formatting


I have the following requirement while using ExecuteWithRegions.

If the date value has got time as : 12:00:00 AM, then the time part should be discarded, else the time part should be displayed.

I have the merge field like this:

What condition I can capply to the above merge field to get the result in the required format?


Hi Sudheer,

Thanks for your inquiry.

I'm afraid it's not clear how exactly you expect the fields to appear. Could you please attach a document which demonstrates a couple examples of how the fields should look?


Thanks Adam.

If the FeeDate is 12/10/2010 11:00:00 AM in database, the merge field value should ve displayed it as 12/10/2010 11:00:00 AM.

If the FeeDate is 12/10/2010 12:00:00 AM in database, the merge field value should ve displayed as just: 12/10/2010.

How do I specify this format condition in a merge field definition?

Hope that answers your question.


Thanks for your request. I think, you can use IFieldMergingCallback to achieve this. For example see the following code:


public void Test001()


Document doc = new Document(@"Test001\in.doc");

doc.MailMerge.FieldMergingCallback = new DateFormater();

doc.MailMerge.Execute(new string[] {"FeeDate"}, new object[] {new DateTime(2011, 7, 27, 11, 0, 0)});



private class DateFormater : IFieldMergingCallback


public void FieldMerging(FieldMergingArgs args)


if (args.FieldName == "FeeDate")


DateTime date = (DateTime)args.FieldValue;

if (date.TimeOfDay.TotalSeconds == 0)

args.Text = date.ToString("MM/dd/yyyy");


args.Text = date.ToString("MM/dd/yyyy hh:mm:ss");



public void ImageFieldMerging(ImageFieldMergingArgs args)


// Do nothing.



Hope this helps.

Best regards,


It works perfectly.