Click here to Skip to main content
11,582,850 members (71,305 online)
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
Nibin22642
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)

  Print Answers RSS
0 OriginalGriff 335
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 124
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2015
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