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.


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:


Anyone have any ideas?


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).


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.

Question Answered as of 3 Years Ago by Mitja Bonca
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

This question has already been solved: Start a new discussion instead
Start New Discussion
View similar articles that have also been tagged: