Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a DateTime variable to get the Month, and then put the value into a string in C#? [VS2005]

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".


2 Answers

DateTime dt = Convert.ToDateTime(dateTimePicker1.Text); //taken the DateTime from form
string dt1 = dt.ToString("MMMM yyyy")
like image 61
Gordon Bell Avatar answered Dec 08 '25 06:12

Gordon Bell


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"
like image 20
Trevor Tubbs Avatar answered Dec 08 '25 07:12

Trevor Tubbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!