Reputation: 862
How can I set the Datetimepicker
-Format to MM/YYYY?
Upvotes: 27
Views: 103591
Reputation: 1
This line worked for me
DateTimePicker1.Value.ToString("MMMM dd yyyy")
output: August 2019
Upvotes: -3
Reputation: 437
This will give you some more options to display date with diff formats.
DateTimerPicker.Format = DateTimePickerFormat.Custom;
DateTimerPicker.CustomFormat = "MM/yyyy"; // this line gives you only the month and year.
DateTimerPicker.ShowUpDown = true;
Below are the different formats to display date alone on the date time picker control of the Windows applciation C#
DateTimerPicker.CustomFormat = "MMMM yyyy";
The above code will display the full month name and year like "August 2018"
DateTimerPicker.CustomFormat = "MMMM yyyy";
The above code will display the full month name, date and year like "08 August 2018"
DateTimerPicker.CustomFormat = "dd MM yyyy";
This line will give the date in the specified format with out forward slash "08 08 2018"
DateTimerPicker.CustomFormat = "dd/MM/yyyy";
This line will give more specific format to the date "08/08/2018"
DateTimerPicker.CustomFormat = "dd/MMM/yyyy";
This line give date in the format of "08/Aug/2018"
Upvotes: 6
Reputation: 3058
You can use DateTimerPicker.Format
property as following:
DateTimerPicker.Format = DateTimePickerFormat.Custom;
DateTimerPicker.CustomFormat = "MMMM yyyy";
DateTimerPicker.ShowUpDown = true;
Note: DateTimerPicker.ShowUpDown = true;
is for making the calendar not visible
Upvotes: 17