SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Parse String into DateTime format

Latest post 07-09-2007 4:06 PM by ChRoss. 4 replies.
  • 06-29-2007 4:34 PM

    • eddykuan
    • Top 50 Contributor
    • Joined on 05-25-2006
    • Singapore
    • Posts 94

    Parse String into DateTime format

    I've a situation here.

     

    Public Shared Function ConvertStringToDateTime(ByVal s As String) As [Object]
                Dim format As New System.Globalization.CultureInfo("en-GB", True)
                Return DateTime.Parse(s, format)
    End Function

     

    This function can't parse the string correctly and throw me the "Object reference not set to an instance of an object." error message.

    I've this line in my Web.config file as well.

     

    <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB" />

     

    When I set the CultureInfo in my ConvertStringToDateTime function to false, or when I remove the format when I parse the string into the DateTime, NO ERROR.

    For more information, my current Regional and Language Options is set to English (United Kingdom).

    Any idea what cause this?

     

    Thanks and regards,

    eddykuan Smile

    unsigned eddykuan... :P
  • 06-29-2007 4:46 PM In reply to

    • eddykuan
    • Top 50 Contributor
    • Joined on 05-25-2006
    • Singapore
    • Posts 94

    Re: Parse String into DateTime format

    oh yeah, forgot this information. i try debug it and step into the function, the string, s, that i pass in was "21/06/2007".

     

    thanx ;)

    unsigned eddykuan... :P
  • 06-29-2007 11:44 PM In reply to

    Re: Parse String into DateTime format

    Check out this link: http://www.developerfusion.co.uk/show/4690/ for your answer. Smile

  • 07-02-2007 1:26 PM In reply to

    • eddykuan
    • Top 50 Contributor
    • Joined on 05-25-2006
    • Singapore
    • Posts 94

    Re: Parse String into DateTime format

    information provided was in deed very useful...

     

    however, the recommendation of using the 'ukCulture.DateTimeFormat' isn't helpful...

     

    same error message still occured...

     

    huh???

     

    unsigned eddykuan... :P
  • 07-09-2007 4:06 PM In reply to

    • ChRoss
    • Top 500 Contributor
    • Joined on 04-17-2007
    • Singapore
    • Posts 4

    Re: Parse String into DateTime format

    Hi Eddy,

    I've tried your code and hit no error. Maybe you can paste the error stack trace here.

    Just curious, why you use Object as the return value type?

Page 1 of 1 (5 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems