How change date format

Last post 05-21-2009 2:01 PM by asaf meir. 7 replies.

Sort Posts:

  • How change date format

    05-25-2005, 7:59 AM
    • Member
      15 point Member
    • pavel_2k
    • Member since 05-25-2005, 11:34 AM
    • Posts 3
    I localize my portal, but date in american format - mm/dd/yyyy.
    How I can display date in dd.mm.yyyy format? When I input date in this format - it's verify on page - and write - "incorrect date".

    Pavel
  • Re: How change date format

    05-25-2005, 10:22 AM
    • Member
      15 point Member
    • pavel_2k
    • Member since 05-25-2005, 11:34 AM
    • Posts 3
    Problem in caching pages of portal. I change in web.config

    <globalization culture="ru-RU" uiCulture="ru" requestEncoding="UTF-8" responseEncoding="UTF-8" fileEncoding="UTF-8" />
    and 
    <add key="DefaultLanguage" value="ru-RU" />

    and it's OK.

    Many changes don't visible - until click "refresh" one+ times.

  • Re: How change date format

    06-07-2005, 1:03 AM
    • Member
      22 point Member
    • thanhtungo
    • Member since 03-18-2003, 12:07 PM
    • Posts 4
    You can change below:
    if you want replace "31/12/2005" with "12/31/2005", you can see below code:

    DateTime d1 = DateTime.ToDate;
    string dd = d1.Day.ToString();
    string mm = d1.Month.ToString();
    string yyyy = d1.Year.ToString();

    string d2 = dd + "/" + mm + "/" + yyyy;
  • Re: How change date format

    11-05-2007, 3:59 AM
    • Member
      4 point Member
    • satyanaresh
    • Member since 10-12-2007, 8:51 AM
    • Posts 2

    this is ok but i want my date format in dd-mon-yyyy

     so what i can do

     

  • Re: How change date format

    01-16-2008, 5:37 PM
    • Member
      64 point Member
    • JimboM
    • Member since 04-02-2003, 6:02 PM
    • Mendocino Coast, CA
    • Posts 22

    You can use ToString with a format specifier...for example, to format this posting date in your format:

     

    DateTime.Today.ToString("dd-MMM-yyyy")
     

     

  • Re: How change date format

    06-06-2008, 3:37 AM

    hi,

    you can use the following,

    DateTime dt = DateTime.Now;

    string[] s = dt.Date.GetDateTimeFormats();

    Response.Write(s[6].ToString() + "&nbsp;<br/>");

    Response.Write(s[5].ToString() + "&nbsp;<br/>");

    Response.Write(s[4].ToString() + "&nbsp;<br/>");

    Response.Write(s[3].ToString() + "&nbsp;<br/>");

    Response.Write(s[2].ToString() + "&nbsp;<br/>");

    Response.Write(s[1].ToString() + "&nbsp;<br/>");

    Response.Write(s[0].ToString() + "&nbsp;<br/>");
  • Re: How change date format

    05-15-2009, 9:30 AM
    • Participant
      1,547 point Participant
    • ctheriault
    • Member since 04-10-2009, 4:33 PM
    • Posts 276

    Use "fr-CH" as culture for you user session (or for your whole appl) and you'll get this very format (I mean "dd.mm.yyyy"). It works fine for MaskEditExtender coupled with a MaskEditValidator and with CalendarExtender as well.

    The "Mask" property seems subordinate to the current culture. "." will be display as separator when current culture is "fr-CH" regarless if you put an "/" in it. ("-" will be displayed if using the "fr-CA" culture (which is mine))

    myControl_MaskedEditExtender.CultureName = MyCurrentSession.CurrentCulture.Name;
    myControl_MaskedEditExtender.Mask = GetCurrentCultureShortDateMask();
    
    
    
     Note: It seems for instance that Ajax needs "/" as separator in the Mask property otherwise I get runtime errors. I use something not very elegant instead, but that's the best I found so far:
        private string GetCurrentCultureShortDateMask()
        {
            bool bln_Got_d = false;
            bool bln_Got_M = false;
            string str_DataPattern = MyCurrentSession.CurrentCulture.DateTimeFormat.ShortDatePattern;
            StringBuilder sb_Mask = new StringBuilder(str_DataPattern.Length);
            foreach (char c in str_DataPattern)
                switch (c) {
                    case 'y':
                        sb_Mask.Append('9'); break;
                    case 'd':
                        if (bln_Got_d)
                            break;
                        bln_Got_d = true;
                        sb_Mask.Append("99");
                        break;
                    case 'M':
                        if (bln_Got_M)
                            break;
                        bln_Got_M = true;
                        sb_Mask.Append("99");
                        break;
                    default: 
                        sb_Mask.Append('/');
                        break;
                }
            return sb_Mask.ToString();
        }
     
    ----
    Don't forget to mark this posting as an "Answer" if it is helpful to you
  • Re: How change date format

    05-21-2009, 2:01 PM
    • Member
      14 point Member
    • asaf meir
    • Member since 01-18-2004, 8:27 PM
    • Israel
    • Posts 11

    make sure to set the LANGUAGE or DATEFORMAT when working with MSSQL

    SQLSERVER default englisg installation results in US style dates - mdy

Page 1 of 1 (8 items)