Date/culture problem

Last post 01-06-2008 1:22 AM by ErrolFlynn1. 15 replies.

Sort Posts:

  • Date/culture problem

    05-14-2007, 7:18 PM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    I have an ASP.NET 2 site, developed in VS2005, running on XP Pro SP2, with IIS 5.1, IE7.

    In the UK, so want european style dd/MM/yyyy date formats.

    Language is set to UK english (en-GB) in windows control panel and web.config.

    When I run the pages inside VS2005, or in VWD express, they display as I would hope and expect.

    If I open the pages directly in IE7 as http://localhost/etc the dates are displayed in MM/dd/yyyy format.

    I added code to display the culture and UI-culture settings on the page - always reports English (United Kingdom) whichever way the dates come out.

    I have tried

    <

    globalization uiCulture="en-GB" culture="en-GB"/>

    and

    <

    globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>

    in the web.config file

    I have also tried setting culture and uiculture on each page. Made no difference. 

     

    If I copy the pages and data base to another machine running what seems to be the same software, the pages always display dates in the desired dd/MM/yyyy format, regardless of whether I view them from VWD or start IE7 from the start menu. 

     

    Is there a language/culture setting somewhere for IIS that I don't know about?

    Any other suggestions?

     

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    05-16-2007, 7:47 AM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    Does nobody have any suggestions at all?

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    05-17-2007, 12:56 AM
    • Loading...
    • manasbbsr
    • Joined on 05-07-2007, 5:32 PM
    • Posts 13

  • Re: Date/culture problem

    05-17-2007, 1:03 AM
    • Loading...
    • manasbbsr
    • Joined on 05-07-2007, 5:32 PM
    • Posts 13

    Filed under:
  • Re: Date/culture problem

    05-17-2007, 5:17 AM
    • Loading...
    • FinnNk
    • Joined on 02-16-2007, 7:57 PM
    • Posts 9

    I am guessing you have checked this already, but just in case - do you have a language other than en-GB higher up the list of preferred languages in IE7 on the machine that has the problem?  (or no en-GB in the list at all)

  • Re: Date/culture problem

    05-17-2007, 7:05 AM
    • Loading...
    • ph9009
    • Joined on 05-17-2007, 10:57 AM
    • Posts 2

    Just to let you know I'm struggling with the exact same issue and have done everything you have done and still get American dates, if you do resolve it I would be interested to know, and likewise if I find a solution I'll let you know.

    Sorry this doesn't help, but at least you know you are not the only one in this boat!!

  • Re: Date/culture problem

    05-17-2007, 9:55 AM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    FinnNk:

    I am guessing you have checked this already, but just in case - do you have a language other than en-GB higher up the list of preferred languages in IE7 on the machine that has the problem?  (or no en-GB in the list at all)

    Thanks for the suggestion, but en-GB is the only language listed in IE7 Internet Options on that machine.

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    05-17-2007, 12:46 PM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    ph9009:

    Just to let you know I'm struggling with the exact same issue and have done everything you have done and still get American dates, if you do resolve it I would be interested to know, and likewise if I find a solution I'll let you know.

    Sorry this doesn't help, but at least you know you are not the only one in this boat!!

    Frustratingly, I have it working perfectly inside VWD express or inside VS2005, but not in IE7 on IIS5.1 on that same machine; and it works fine on another machine with exactly same software (as far as I can see), both inside VWD and in IE7 + IIS 5.1 too.

    What configuration are you on?

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    05-18-2007, 4:14 AM
    • Loading...
    • ph9009
    • Joined on 05-17-2007, 10:57 AM
    • Posts 2

    Exactly the same...

     Though I've done some further investigations and have noticed that my server LCID is always 1033 and have had to set it 'session:LCID = 2057' in session_start in GLOBAL.ASA, but still my dates display correctly in VS2005 but not when run directly in IE7.

     After I set this session LCID value I decided to just display a number i.e. response.write(FormatCurrency(120)) and I get the correct country settings, however a date is wrong - weired!!!!

     Did the following:

     Dim myDTFI As DateTimeFormatInfo = New CultureInfo("en-GB", False).DateTimeFormat

     Dim myDT As New DateTime

     myDT = date.today

     response.write(myDT.ToString("d"))

     And date is still wrong, however if i change 'd' to 'D' I get the correct long day format i.e  18 May 2007 - talk about being confused.

     My problem might be down to DateValue function as I use this when building up a data object, I get my data from sever webservices that I then build into a data object which I use as a data source for my grid viewer, so I'm storing a string value for the date, converted originally by DateValue - this is the function that works ok in VS2005 but not in IE7, I've currently changed my code to use the above code to display the long date format, but have not done any data entry as of yet.

     Probably experiment later using the date directly...

  • Re: Date/culture problem

    05-21-2007, 4:43 PM
    • Loading...
    • Motley
    • Joined on 10-14-2005, 5:26 PM
    • West Chicago, IL
    • Posts 2,296
    • TrustedFriends-MVPs

    Try:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim cult As New System.Globalization.CultureInfo("en-GB")

    Dim myDT As New DateTime

    myDT = Date.Today

    Response.Write(myDT.ToString("d", cult))

    Response.End()

    End Sub

    worked fine for me.

    This also works:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim myDT As New DateTime

    myDT = Date.Today

    System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB")

    Response.Write(myDT.ToString("d"))

    Response.End()

    End Sub

  • Re: Date/culture problem

    05-21-2007, 4:57 PM
    Answer
    • Loading...
    • Motley
    • Joined on 10-14-2005, 5:26 PM
    • West Chicago, IL
    • Posts 2,296
    • TrustedFriends-MVPs

    You should have this in your web.config:

    <globalization culture="auto:en-US" uiCulture="auto:en-US"/>

    (Change en-US to whatever your want your default culture to be if the client does not request one)

    Make sure there is no mention of culture or uiculture in the <% Page %> section of your web page.  If they are listed, remove those attributes (And the values) completely.

  • Re: Date/culture problem

    05-22-2007, 6:40 AM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    Thank you for that suggestion, but I am afraid that is not the solution.

    I added the "auto" to the globalization line in web.config, and made sure there was no culture or uiculture in the <%Page %> line.

    Made no difference to the results; 31/12/2007 from inside VS, 12/31/2007 from typing the url into the IE address bar. 

    And another variation on the page, with templates in the detailsview, works fine from VS, but not when I type the page url in the IE address bar. The template works in display mode, but not in Edit mode. The date is displayed as 31/12/2007, but if I change it to 30/12/2007 it is rejected; when I retype it as 12/30/2007 it is accepted.

     

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    05-22-2007, 8:44 AM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    Motley:

    Try:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim cult As New System.Globalization.CultureInfo("en-GB")

    Dim myDT As New DateTime

    myDT = Date.Today

    Response.Write(myDT.ToString("d", cult))

    Response.End()

    End Sub

    worked fine for me.

    This also works:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim myDT As New DateTime

    myDT = Date.Today

    System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-GB")

    Response.Write(myDT.ToString("d"))

    Response.End()

    End Sub

     

    Thank you for the suggestion, but the symptoms are the same.

    It works when I right click the page and "view in browser" from inside VS. Date displayed as 22/05/2007.

    It doesn't work when I type the url http://localhost/mypage in the ie7 address bar - the date is displayed as 5/22/2007.

     

     

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    05-22-2007, 9:48 AM
    • Loading...
    • LockH
    • Joined on 03-25-2007, 2:58 PM
    • Scotland, where whisky has no e.
    • Posts 575

    I have an even simpler page, displaying a date and the culture and short and long date format settings.

    Run from VS2005 right-click View in Browser it shows:

    22/05/2007
    Culture is set as English (United Kingdom)
    UICulture is set as English (United Kingdom)
    Short Date Format is set as dd/MM/yyyy
    Long Date Format is set as dd MMMM yyyy

    mini.aspx Culture and date settings.

     

     

    Run from IE7 url bar it shows:

     5/22/2007
    Culture is set as English (United Kingdom)
    UICulture is set as English (United Kingdom)
    Short Date Format is set as M/d/yyyy
    Long Date Format is set as dd MMMM yyyy

    mini.aspx Culture and date settings.

     

    The date is displayed differently, and the short date format string is different, even though the culture and UIculture are always English (United Kingdom).

    Is this an IIS 5.1 configuration issue? 

    Is there any way to set the date format in the config, other than using the culture and UICulture? 

     

     

    Code follows:

    <script runat="server">

    protected void Page_Load(object sender, EventArgs e)

    {

    DateTime myDT = new DateTime() ;myDT = DateTime.Today;

     

    Response.Write(myDT.ToString("d"));

    Response.Write("<br /> Culture is set as " + System.Globalization.CultureInfo.CurrentCulture.EnglishName.ToString());

    Response.Write("<br /> UICulture is set as " + System.Globalization.CultureInfo.CurrentUICulture.EnglishName.ToString());

    Response.Write("<br /> Short Date Format is set as " + System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.ToString());

    Response.Write("<br /> Long Date Format is set as " + System.Globalization.DateTimeFormatInfo.CurrentInfo.LongDatePattern.ToString());

    }

    </script>

     

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
  • Re: Date/culture problem

    01-06-2008