How to get only the date value from a Windows Forms DateTimePicker control?

前端 未结 9 1677
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 03:21

I\'m building an application with C# code.
How do I get only the date value from a DateTimePicker control?

9条回答
  •  梦如初夏
    2021-01-30 03:30

    I'm assuming you mean a datetime picker in a winforms application.

    in your code, you can do the following:

    string theDate = dateTimePicker1.Value.ToShortDateString();
    

    or, if you'd like to specify the format of the date:

    string theDate = dateTimePicker1.Value.ToString("yyyy-MM-dd");
    

提交回复
热议问题