Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi Friends,
 
I need a help to solve this issue:
 
Below is my Code:
 
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 25-Jan-13 4:34am
Nibin22595
Edited 25-Jan-13 4:43am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your ParseExact format is wrong:
Dim Time As DateTime = DateTime.ParseExact(Value, "dd-MMM-yyyy", CultureInfo.InvariantCulture)
Expects the date as "25-Jan-2012"
You want
Dim Time As DateTime = DateTime.ParseExact(Value, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Which expects "25/01/2012"
  Permalink  
Comments
Nibin22 at 25-Jan-13 11:12am
   
Thanks !!!
Your Solution is correct !!!
OriginalGriff at 25-Jan-13 11:28am
   
You're welcome!
Marcus Kramer at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100