System.FormatException: String was not recognized as a valid DateTime.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajprakash
    New Member
    • Feb 2007
    • 70

    System.FormatException: String was not recognized as a valid DateTime.

    Hi all,
    i have created a web application on my location (India) and when i run the application it's run fine, but when i host this application in autralia then the above errors occours by the following line

    DateTime WhenDtg = Convert.ToDateT ime(DateTime.No w.ToString("MM/dd/yyyy HH:mm:ss"));


    i am not getting the solution.
  • mikeyeli
    New Member
    • Oct 2007
    • 63

    #2
    Originally posted by pankajprakash
    Hi all,
    i have created a web application on my location (India) and when i run the application it's run fine, but when i host this application in autralia then the above errors occours by the following line

    DateTime WhenDtg = Convert.ToDateT ime(DateTime.No w.ToString("MM/dd/yyyy HH:mm:ss"));


    i am not getting the solution.
    my guess is, its a Culture issue, a date's format in India is not the same as in Australia.

    Read the following: Developing World Ready Applications,

    theres a part in that section where it talks about formatting Date and Time for a Specific Culture.

    Comment

    • pankajprakash
      New Member
      • Feb 2007
      • 70

      #3
      Originally posted by mikeyeli
      my guess is, its a Culture issue, a date's format in India is not the same as in Australia.

      Read the following: Developing World Ready Applications,

      theres a part in that section where it talks about formatting Date and Time for a Specific Culture.

      i had also change the culture but the problem remain the same.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Question:
        Whay are you doing that line at all?

        Code:
        DateTime WhenDtg = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
        All you're doing there is taking a DateTime object, making it a string, then trying to make it a DateTime object again. That is a big waste. DateTime is not stored "in a format", that is just for displaying purposes.

        Code:
        DateTime WhenDtg = DateTime.Now;

        Comment

        • mikeyeli
          New Member
          • Oct 2007
          • 63

          #5
          yeah, Plater has a good point there...no need to do that.

          Comment

          Working...