Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Convert String to Date

Posted on 2013-06-01
2
Medium Priority
?
468 Views
Last Modified: 2013-06-06
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
Comment
Question by:rye004
2 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 2000 total points
ID: 39213705
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
 

Author Closing Comment

by:rye004
ID: 39226875
Perfect!  Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question