none
Mailmerge - date format changing in merge document RRS feed

  • Question

  • In the Excel datasource the date format is YYYY-MM-DD but when the merge is done the date format ends up mm/dd/yyyy.  How to keep the same as the datasource ?  Note that this merge is  done with a C#.net application that was rewritten from a Vb6 application.  Since the docs and data sources were created as .doc and .xls when the VB6 application was created they have remained the same filetypes for the C#.net version.  Note when the merge is done with the old vb6 application the date form is the same as the datasource for the merge.  Problem is with the C#.net application doing the mail merge.
    Thursday, May 14, 2015 4:41 PM

Answers

  • Hi,

    >>In the Excel datasource the date format is YYYY-MM-DD but when the merge is done the date format ends up mm/dd/yyyy

    The data format will be effected by your OS date format, I have made a test to do a mail merge, after resetting the OS date format to “yyyy-MM-DD”, the data field in Preview  results has been the expected data format. You may need to reset your OS date format or when fill this field into doc template, you could take DateTime.ToString Method () to input a string in for this date field.

    Hope this could help you.

    Best Regards

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by apepper Tuesday, May 19, 2015 7:44 PM
    Friday, May 15, 2015 9:48 AM
    Moderator

All replies

  • Hi,

    >>In the Excel datasource the date format is YYYY-MM-DD but when the merge is done the date format ends up mm/dd/yyyy

    The data format will be effected by your OS date format, I have made a test to do a mail merge, after resetting the OS date format to “yyyy-MM-DD”, the data field in Preview  results has been the expected data format. You may need to reset your OS date format or when fill this field into doc template, you could take DateTime.ToString Method () to input a string in for this date field.

    Hope this could help you.

    Best Regards

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by apepper Tuesday, May 19, 2015 7:44 PM
    Friday, May 15, 2015 9:48 AM
    Moderator
  • Hi apepper

    When you test, is the vb6 and C# code working in the same environment (version of Windows, version of Word, version of Excel, same language settings, etc.)? If not, what's different? (And please tell us what you're using!)

    Besides the options Lan proposes, another possibility would be to add a date/time switch to the target Mergefield(s). Manually, this would be done by pressing Alt+F9, adding the switch ( { Mergefield "[DateFieldName]" \@ "yyyy-mm-dd" }

    To do this from your code "on the fly", you'd change the field's code using the Field.Code property.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, May 19, 2015 5:57 PM
    Moderator
  • Hi Lan,

    Thanks .  Changing the OS date format for the short date does the trick.  Is there a way to change OS date format short date via C#.net  for one application that needs it as YYYY-MM-DD and then when done change it back to MM/DD/YYYY ?

    Tuesday, May 19, 2015 7:48 PM
  • Hi Cindy,

    Thank you for the reply. As a test, I had already manually added the date formating to one date merge field in one of my doc files as you mentioned and it does work.  But this would have to be done mutltiple times for about 900 doc files that are repeatily used.  Unfortunately it would be difficult to do this on the fly because none of the merge fields that contain date data have any easily identifiable characteristics except for the data itself.

    Tuesday, May 19, 2015 8:14 PM
  • Hi apepper

    Actually, the Mergefields are uniquely identifiable "under the covers". They're members of the Document.MailMerge.Fields collection, which you can loop (ForEach), query its code (what you see if you press Alt+F9 to toggle between field code and field result view), and based on the string the code returns you can check the name of the field in the data source - { MERGEFIELD [FieldName] }, edit the code to append/change the date format and write it back to the field.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, May 20, 2015 6:02 PM
    Moderator