Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Convert String to Date

Posted on 2013-06-01
2
Medium Priority
?
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

661 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