DateTime dt = Convert.ToDateTime(dateTimePicker1.Text); //taken the DateTime from form
string dt1 = String.Format("Y", dt); //trying to make so that it comes to "August 2009"
Tried but all I get is dt1="Y".
DateTime dt = Convert.ToDateTime(dateTimePicker1.Text); //taken the DateTime from form
string dt1 = String.Format("Y", dt); //trying to make so that it comes to "August 2009"
Tried but all I get is dt1="Y".
DateTime dt = Convert.ToDateTime(dateTimePicker1.Text); //taken the DateTime from form
string dt1 = dt.ToString("MMMM yyyy")
DateTime dt = Convert.ToDateTime(dateTimePicker1.Text); //taken the DateTime from form
string dt1 = String.Format("{0:MMMM yyyy}", dt); //trying to make so that it comes to "August 2009"
You have other answers that use ToString
.. if you want to use string.Format
, try this:
string dt1 = string.Format("{0:Y}", dt);
The other answers will work. I just wanted to comment on the reason why your code doesn't work. String.Format
is designed to format more than 1 variable at the same time. You could use it, but the syntax would be:
string str = String.Format("{0:Y}", dt);
hope that helps. The format specifier you're looking for is probably "MMMM yyyy", the default format for "Y" is year-month, not month-year.