Reputation: 173
I am trying to convert my date string to MonthDate format
Date string is in this format "08-07-2016 00:00:00"
I need this output: July 8
I am trying String.Format("{0:ddd, MMM d, yyyy}", dt)
but it is not working.
Upvotes: 1
Views: 104
Reputation: 2063
If your date is a string, try this :
string myDate = "08-07-2016 00:00:00";
DateTime myDateValue = DateTime.ParseExact(myDate, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None);
string myDateString = string.Format("{0: MMMM d}", myDateValue);
Upvotes: 1
Reputation: 11
Have you tried the following?:
date.ToString("MMMM d")
Example:
DateTime date = DateTime.Parse("08-07-2016 00:00:00");
Console.WriteLine(date.ToString("MMMM d"));
Results to: July 8
Upvotes: 1
Reputation: 7656
Try this:
string.Format("{0:MMMM d}", dt);
In C# 6.0 you can do it like this:
$"{dt:MMMM d}";
With "MMM"
you get the short version of each month. With "MMMM"
you get the full name.
Upvotes: 2
Reputation: 45947
replace
String.Format("{0:ddd, MMM d, yyyy}", dt)
with
String.Format("{0:MMMM d}", dt)
MMMM
is the name of the monthd
is the day without leading 0Reference: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
Upvotes: 6