Solved

C# Convert String to Date

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now