Click here to Skip to main content
12,944,138 members (61,199 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Nibin22667
Updated 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 25-Jan-13 11:12am
   
Thanks !!!
Your Solution is correct !!!
OriginalGriff 25-Jan-13 11:28am
   
You're welcome!
Marcus Kramer 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,643
CHill60 2,970
Maciej Los 2,348
Jochen Arndt 1,900
ppolymorphe 1,765


Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2017
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