Deepika Thakur
Deepika Thakur

Reputation: 173

Date string to monthdate format

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

Answers (4)

Rom Eh
Rom Eh

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

Michael Miranda
Michael Miranda

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

diiN__________
diiN__________

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

fubo
fubo

Reputation: 45947

replace

String.Format("{0:ddd, MMM d, yyyy}", dt)

with

String.Format("{0:MMMM d}", dt)
  • MMMM is the name of the month
  • d is the day without leading 0

Reference: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Upvotes: 6

Related Questions