Date problem.
Hello my fellow daniwebbers, I have yet another question.
I have a date, which is pulled from a database, that I need to convert to another form of that date.
Example.
Date1: 1/2/2001
Date2: 01/02/2001
What i am wanting to do is turn the current date format into two digit month/day with four digit year.
Here is the problem.
Upon converting the date, the return result is the format string??
What I have tried:
String.Format
String.FormatDateTime
DateTime.TryPaseExact
Anyone have any ideas?
Related Article: How to validate string format vb.net
is a solved VB.NET discussion thread by jbutardo that has 10 replies, was last updated 1 year ago and has been tagged with the keywords: format, string, validation, vb.net.
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8
try it this way:
string date1 = "1/2/2001";
DateTime date = Convert.ToDateTime(date1);
//this is what you have to do:
string date2 = date.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
My 1st two lines of code are only example to get an actual date (you already have a date from database).
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Found the solution.
Had to double parse the dates.
One string split to remove the space, then another to remove the /'s
Then use the pad function to add the 0's.
On the other hand, thanks for the suggestions Bonca.
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8
Question Answered as of 1 Year Ago by
Mitja Bonca