Solved

C# Convert String to Date

Posted on 2013-06-01
2
449 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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