Reputation: 341
is there are better way to structure this line of code, as you can see, I am changing the format of a string that contains a date.
lblCourseStartDate.Text = String.Format("{0:D}", DateTime.Parse(CourseStartDate));
I just found it untidy that I am converting twice or three times to get the format I want.
Thanks
Upvotes: 1
Views: 159
Reputation: 16680
You can do DateTime.Parse(CourseStartDate)).ToLongDateString()
or DateTime.Parse(CourseStartDate)).ToString("D")
, which might be a little cleaner. But, you're basically stuck doing the Parse and then the Format regardless of what you do.
Upvotes: 3