SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Parse String into DateTime format

rated by 0 users
This post has 4 Replies | 0 Followers

Top 50 Contributor
Posts 94
eddykuan Posted: 06-29-2007 4:34 PM

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
Top 50 Contributor
Posts 94

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
Top 25 Contributor
Posts 156

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

Top 50 Contributor
Posts 94

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
Top 500 Contributor
Posts 4

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