Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

C# Convert String to Date

I have the following date format as a string which I am trying to convert to DateTime in C#

8:46 AM - 30 Dec 11

Anyone have a suggestion for this?

Many Thanks!
0
rye004
Asked:
rye004
1 Solution
 
clockwatcherCommented:
You can use the DateTime.ParseExact method and specify your format.

"h:mm tt - d MMM yy"

using System;

public class DTP 
{
	public static void Main() 
	{
		string s = "8:46 AM - 30 Dec 11";
		DateTime d = DateTime.ParseExact(s, "h:mm tt - d MMM yy", null);
		System.Console.WriteLine(d);
	}
}

Open in new window


The various format options are detailed here: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
0
 
rye004Author Commented:
Perfect!  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now