How do I format a DateTime variable to get the month and then put the value into a string in C #? [VS2005]
6 answers
Other answers will work. I just wanted to comment on the reason why your code is not working. String.Format
is designed to format more than 1 variable at a time. You could use it, but the syntax would be:
string str = String.Format("{0:Y}", dt);
hope this helps. The format specifier you are looking for is probably "MMMM yyyy", the default format for "Y" is year-month, not month-year. In the meantime, there is no need to worry about it.
+2
source to share