We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,348 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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?

2
Contributors
2
Replies
3 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0597 seconds using 2.65MB