chuckd
chuckd

Reputation: 14530

Convert datetime to string with month name and day name

Is there a way to convert a datetime like 1/28/2016 to Friday January 28 2016 in C#?

I'm using .ToShortDateString() to remove the time. I just want the date.

Upvotes: 0

Views: 5948

Answers (3)

C. Entwistle
C. Entwistle

Reputation: 31

You can use .ToLongDateString() instead. For example:

DateTime myDateTime = new System.DateTime(2001, 5, 16, 3, 2, 15);
Console.WriteLine(myDateTime.ToLongDateString());

This will output "Wednesday, May 16, 2001" to the console window.

Upvotes: 3

Marcin Bator
Marcin Bator

Reputation: 381

While converting date to string you can set its format

someDate.ToString("dddd MMMM d yyyy");

should give you format you need.

.ToLongDateString()

should also work, but it doesn't give you customization capabilities.

You can find out more about date formatting here: Custom Date and Time Format Strings

Upvotes: 3

Use the DateTime.ToLongDateString() function, it is designed to fulfill your requirement.

Upvotes: 5

Related Questions