Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. date.parse problem

date.parse problem

Scheduled Pinned Locked Moved ASP.NET
helpsysadminwindows-admindebuggingquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    todd 01011101
    wrote on last edited by
    #1

    Hello I have been trying to debug a problem with a web app that I am responsible for and have traced it down to a very specific problem. To demonstrate that problem, I have written a little web app, and I'm sure someone here can direct me quickly to the source of the problem.

       Try
            Me.Label1.Text = ""
            Me.Label1.Text = Date.Parse(Me.TextBox1.Text).ToShortDateString
        Catch ex As Exception
            Me.Label1.Text = ex.Message
        End Try
    

    When I run this on serverA it with the input of '7/30/2007' it fails with the exception message being: 'String was not recognized as a valid DateTime' When I run it on any other server, it works fine. On serverA, if I input '30/1/2007' it works. If I input that value on any of my other servers it fails with 'String was not recognized as a valid DateTime' The question is, what server configuration value do I need to change on the server to make that server behave the same as the other servers. These are all windows server 2003 servers, and I checked the regional settings in Control panel and the failing and passing servers have the same regional settings values (english US) and the same long/short date format in the regional settings. Apparently that does not affect this date.parse behavior. This kind of problem scares me because it introduces a significant likelihood of wierd flaky problems and behavior. If the date value had been '2/5/2007' it would've worked on both servers and it would have been hard to identify why all the data was messed up. Any help or guidance would be appreciated.

    C 1 Reply Last reply
    0
    • T todd 01011101

      Hello I have been trying to debug a problem with a web app that I am responsible for and have traced it down to a very specific problem. To demonstrate that problem, I have written a little web app, and I'm sure someone here can direct me quickly to the source of the problem.

         Try
              Me.Label1.Text = ""
              Me.Label1.Text = Date.Parse(Me.TextBox1.Text).ToShortDateString
          Catch ex As Exception
              Me.Label1.Text = ex.Message
          End Try
      

      When I run this on serverA it with the input of '7/30/2007' it fails with the exception message being: 'String was not recognized as a valid DateTime' When I run it on any other server, it works fine. On serverA, if I input '30/1/2007' it works. If I input that value on any of my other servers it fails with 'String was not recognized as a valid DateTime' The question is, what server configuration value do I need to change on the server to make that server behave the same as the other servers. These are all windows server 2003 servers, and I checked the regional settings in Control panel and the failing and passing servers have the same regional settings values (english US) and the same long/short date format in the regional settings. Apparently that does not affect this date.parse behavior. This kind of problem scares me because it introduces a significant likelihood of wierd flaky problems and behavior. If the date value had been '2/5/2007' it would've worked on both servers and it would have been hard to identify why all the data was messed up. Any help or guidance would be appreciated.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This is asked so often. The regional settings are obviously different, no matter what you think, and either way, apart from the terrible naming conventions, no production code should ever use Date.Parse, that's what Date.TryParse is for. I wouldn't actually sack someone for writing this code, but there's quite a number of htings I'd be having a talk to them about. You will always face this issue - if you're moving dates from strings, you risk getting the wrong dates unless you can be sure of the setup on the server. Either way, it's best avoided. I'm all for using a 17 Feb 1969 format, as it's unambiguous.

      Christian Graus Driven to the arms of OSX by Vista.

      T 1 Reply Last reply
      0
      • C Christian Graus

        This is asked so often. The regional settings are obviously different, no matter what you think, and either way, apart from the terrible naming conventions, no production code should ever use Date.Parse, that's what Date.TryParse is for. I wouldn't actually sack someone for writing this code, but there's quite a number of htings I'd be having a talk to them about. You will always face this issue - if you're moving dates from strings, you risk getting the wrong dates unless you can be sure of the setup on the server. Either way, it's best avoided. I'm all for using a 17 Feb 1969 format, as it's unambiguous.

        Christian Graus Driven to the arms of OSX by Vista.

        T Offline
        T Offline
        todd 01011101
        wrote on last edited by
        #3

        I love pompous know-it-all responses that don't answer the question. Christian, it seemed pretty obvious that the code was written for purposes of demonstrating the problem and was not supposed to be "production code". Feel free to spend as much time as you'd like refactoring it and bringing it up to your standard. I did some additional reading, and found this very helpful knowledge base article about stabilizing culture specific behavior in asp.net apps - if anyone else has a similar question in the future.. http://support.microsoft.com/kb/326943[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups