Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I need a help to solve this issue:

Below is my Code:

VB
Dim Time As DateTime = DateTime.ParseExact(Value, "dd-MMM-yyyy", CultureInfo.InvariantCulture)
Dim TimeString As String = Time.ToString("dd-MMM-yyyy")
TextBox.Text = TimeString


Value is the String which is having Value as : '08/12/2012' i.e in 'dd/MM/yyyy'.
And my actual need is to convert this data from DB to '08-DEC-2012' i.e in 'dd-MMM-yyyy' format.

But i am struck to get that due to the following error :

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


Please help me to sort this problem.
Thanks in advance !!!
Posted
Updated 25-Jan-13 4:43am
v3

1 solution

Your ParseExact format is wrong:
VB
Dim Time As DateTime = DateTime.ParseExact(Value, "dd-MMM-yyyy", CultureInfo.InvariantCulture)
Expects the date as "25-Jan-2012"
You want
VB
Dim Time As DateTime = DateTime.ParseExact(Value, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Which expects "25/01/2012"
 
Share this answer
 
Comments
Nibin22 25-Jan-13 11:12am    
Thanks !!!
Your Solution is correct !!!
OriginalGriff 25-Jan-13 11:28am    
You're welcome!
fjdiewornncalwe 25-Jan-13 12:58pm    
+5. Of Course.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900