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

前端 未结 9 1598
爱一瞬间的悲伤
爱一瞬间的悲伤 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:28

    I had this issue when inserting date data into a database, you can simply use the struct members separately: In my case it's useful since the sql sentence needs to have the right values and you just need to add the slash or dash to complete the format, no conversions needed.

    DateTimePicker dtp = new DateTimePicker();
    String sql = "insert into table values(" + dtp.Value.Date.Year + "/" + 
    dtp.Value.Date.Month + "/" + dtp.Value.Date.Day + ");";
    

    That way you get just the date members without time...

提交回复
热议问题