How can I set the datetimepicker dropdown to show Months only

前端 未结 5 976
夕颜
夕颜 2020-12-17 16:45

So instead of this showing up on clicking the dropdown menu.

I want the dropdown to be like this when clicked.

Thanks a lot for any help.

5条回答
  •  抹茶落季
    2020-12-17 17:04

    Try the following code:

    DateTime newDateValue = new DateTime(dateTimePicker_month.Value.Year, 1, 1);
    dateTimePicker_month.Value = newDateValue;
    dateTimePicker_month.Format = DateTimePickerFormat.Custom;
    dateTimePicker_month.CustomFormat = "MMM-yyyy";
    dateTimePicker_month.ShowUpDown = true;
    

    You have to add (1,1) for february month which having 28/29 days to ascertain the all the month values.If you want the query to select month.Following is an example:

    string month = dateTimePicker_month.Value.Month.ToString();
    string year = dateTimePicker_month.Value.Year.ToString();
    

    use the following query to select month:

    select CAST(date AS DATE) from table where DATEPART(month, date)  = '" + month + "' and DATEPART(year,date) = '" + year + "' 
    

提交回复
热议问题