0

I have datetime like:

01-Jan-10 12:00:00 AM I want to get only 01-Jan-10.I do not know how to convert it. Anyone know help me please, Thanks,

2
  • 1
    Can you please elaborate a bit more? Are you saying you have a string in that format and want to put it into a DateTime variable or are you saying you have a DateTime variable and want to get a string out with only the date and no time? Commented Aug 7, 2012 at 16:04
  • See Custom Date and Time Format Strings Commented Aug 7, 2012 at 16:06

3 Answers 3

4

If you have a DateTime object and want to get the string in that format, use myDateTime.ToString("dd-MMM-yy"). If you have a DateTime object and want to return a new DateTime object that is just the date component, use DateTime.Date.

Sign up to request clarification or add additional context in comments.

2 Comments

It wouldn't hurt to note that, since MMM results in a culture specific value that the OP should specify the culture if they really always want the string Jan
@Maly, when you look at answers to your questions you'll see a small gray checkmark underneath the votes for each answer. When you have an answer that you consider to correctly address your question, please click the checkmark to accept that answer. In order to assist the StackOverflow community you should do this for all of your questions that have received helpful answers.
0

Like this:

DateTime dt = DateTime.Today; //or whatever
string dateString = dt.ToShortDateString();

You can also use ToString() to format it however you like. In your case, it would be:

string dateString = dt.ToString("dd-MMM-YY");

Comments

0

use method DateTime.ToShortDateString(); or DateTime.ToLongDateString()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.