none
How to remove the trailing dot in the date time format MMM in Spanish (Windows Server 2012R2) RRS feed

  • Question

  • I have the following code:

    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-ES");
    button2.Text = DateTime.Now.ToString("dd MMM yyyy");

    When I run this code on a Win7 machine, I get the month without a trailing dot (i.e. jun)
    When I run this code on a Windows 2012 R2 server, I get the month with a trailing dot (jun.)

    Although this is not a major issue when displaying the date.  If in a web page the date text is changed to a value without the dot and returned to the Windows 2012 R2 webserver, the parsing of the date fails.

    DateTime.ParseExact(<text>,"dd MMM yyyy" , null);

    This has been working on W2008 webservers.  However we recently upgraded the infrastructure which has caused the problem.  Please can someone let me know if there is a way to prevent the trailing dot being included in the Spanish localised month?

    Regards

    Nick

    Wednesday, June 8, 2016 2:15 PM

Answers

  • Maybe check if “es-US” or “es-VE” can be used instead of “es-ES”. Then you will only need a minor change.


    Thursday, June 9, 2016 8:47 AM

All replies

  • Seems that it is possible to adjust the name of the months. The next example creates the opposite date format, then uses ToString, where you have to specify the used format:

    var ci = new CultureInfo( "es-ES" );
    
    var dtf1 = ci.DateTimeFormat;
    var dtf2 = (DateTimeFormatInfo)dtf1.Clone();
    
    dtf2.AbbreviatedMonthNames = dtf1.AbbreviatedMonthNames.Select( m => m.TrimEnd( '.' ) ).ToArray();
    dtf2.AbbreviatedMonthGenitiveNames = dtf1.AbbreviatedMonthGenitiveNames.Select( m => m.TrimEnd( '.' ) ).ToArray();
    
    string s1 = DateTime.Now.ToString( "dd MMM yyyy", dtf1 ); // e.g. "08 jun. 2016"
    string s2 = DateTime.Now.ToString( "dd MMM yyyy", dtf2 ); // e.g. "08 jun 2016"

    Therefore, use dtf2.

    The parsing is:

    string s = "08 jun 2016";
    DateTime dt = DateTime.ParseExact( s, "dd MMM yyyy", dtf2 );

    For convenience, maybe accept both of the formats while parsing (using two TryParse).

    However, since even Window 10 uses the new format, probably you should not remove the dot in your outputs.





    Wednesday, June 8, 2016 7:58 PM
  • Thanks for your reply.

    The problem I have is that this is in a production website, and I do not want to make any changes to the code.  I was expecting that there would be a .NET or server configuration change that could be made to revert the abbreviated month names to the names without the trailing dot.

    Thursday, June 9, 2016 8:15 AM
  • Maybe check if “es-US” or “es-VE” can be used instead of “es-ES”. Then you will only need a minor change.


    Thursday, June 9, 2016 8:47 AM
  • Hi... after 2 years, this problem persists, and have migrated to newer OS, like win10.

    This does introduce a parsing problem, not only on websites, but also on any parsing <g class="gr_ gr_93 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="93" id="93">sistem</g>, like vb script, or <g class="gr_ gr_113 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="113" id="113">escel</g> macro.

    Any workarround?

    Thursday, July 5, 2018 1:54 PM