How to force date format to custom format.

I have a program whose default UI culture is German. I also have satellite dlls with English and Catalan resources. The program shall run in Spain with Catalan UI. We have an English Windows XP with German and Spanish MUI packages installed, and English as well as German UI work fine from our program when selected as UI languages in Windows respectively. But how can I get it to show the Catalan UI When I turn on Spanish Windows UI I get the German UI (as it is the default) in our program and I cannot install the Catalan LIP as it requires a native Spanisch Windows XP as a requirement for installation which we don't have. As our customer in Spain insists on it I would like to know how can I tell the program to use the Catalan resources
Thanks,
Daniel Schloser


Answer this question

How to force date format to custom format.

  • ivanL

    Hi Celerno,

    I suspect that U use a string concatenation to create your update statement to sql-server
    So something like:
    string sqlUpdate = "update MYTABLE set mydatetimecolumn = " + datetimevalue.ToString() + " where x=...";

    that can cause problems when the cultures or datetime formats are different. I suggest that U use parameterized queries to solve this problem. To do this create a update statement like this:

    string sqlUpdate = "update MYTABLE set mydatetimecolumn = @datetimevalue where x=...";

    and create a SqlCommand object and add a parameter to the command object like:

    sqlCommand.Parameters.Add("@datetimevalue", datetimevalue);

    datetimevalue must be a DateTime object! (or SqlDateTime )

    Hope this helps.

    Sandor


  • Craig0111

    Hi Daniel,

    You can set the UI culture programatically using:

    System.Threading.Thread.CurrentUICulture = new CultureInfo("es- ");

    maybe this will help. (please replace the with the correct catalan culture)

    I suspect that you can only select spanish culture in windows and not spanish-catalan so the system will look for a spanish culture and not for the more specific spanish-catalan culture. When it can not find the spanish culture it will default to the default culture.

    Sandor


  • thmccarthy

    Thanks, that was helpfull.
  • Duane Douglas

    It worked beautifully, thank you. I added the following lines before InitializeComponent in my main form constructor:

    if (Thread.CurrentThread.CurrentCulture.Name == "ca" || Thread.CurrentThread.CurrentCulture.Name == "ca-ES")

    if (Thread.CurrentThread.CurrentUICulture.Name != "ca" && Thread.CurrentThread.CurrentUICulture.Name != "ca-ES")

    Thread.CurrentThread.CurrentUICulture = new CultureInfo("ca");

    I don't know if it is the official or recommended way so if someone has something to comment I would be glad to hear it.


  • Martijn Mulder

    Please let me know if it solved your problem!

    Sandor


  • zaph

    Hi, the real problem is with the current format of my system, its "dd/mm/yyyy hh:mm:ss a.m.", this cause sql update fails because not recognize this kind of string to update a datetime... but, in case if i give "dd/mm/yyyy hh:mm:ss am" the problem disappear.

    i have no problem in change my pc regional settings... but i don't think do that with pc's Custumers...

    i try already with this:

    CultureInfo myCI = Thread.CurrentThread.CurrentCulture;

    myCI.DateTimeFormat.AMDesignator = "am";

    myCI.DateTimeFormat.PMDesignator = "pm";

    Thread.CurrentThread.CurrentCulture=myCI;

    but it not works... can some one help me ...

    thanks in advance... i know it's a simple and small problem, causes me headache...


  • How to force date format to custom format.