Reputation: 4868
I have a date in this format "MM/dd/yyyy".
string date = "03/30/2017"
I want to convert this string to this format- Thursday, March 30, 2017
.
How can I do this ?
Thank you
Upvotes: 0
Views: 96
Reputation: 236188
You can parse string to DateTime
object and then use DateTime.ToLongDateString()
to get string in required format:
var str = "03/30/2017";
var date = DateTime.ParseExact(str, "MM/dd/yyyy", CultureInfo.InvariantCulture);
var formatted = date.ToLongDateString();
Note that formatted string is culture sensitive. For en-US culture formatted string will be exactly in format which you want:
"Thursday, March 30, 2017"
You can also specify exact format manually, just as with parsing part:
var formatted = date.ToString("dddd, MMMM d, yyyy");
Check Custom Date and Time Format Strings for reference.
Upvotes: 5
Reputation: 248
You should parse it by using
string date = "03/30/2017";
DateTime datetime = DateTime.Parse(date);
string nameddate = datetime.ToString("dddd,MMMMM dd, yyyy");
Other format options are found at https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
Upvotes: 1