I'm building an application with C# code.
How do I get only the date value from a DateTimePicker
control?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Try this
store can be anything entity object etc.
You mean how to get date without the time component? Use DateTimePicker.Value.Date But you need to format the output to your needs.
I'm assuming you mean a datetime picker in a winforms application.
in your code, you can do the following:
or, if you'd like to specify the format of the date:
Following that this question has been already given a good answer, in WinForms we can also set a Custom Format to the DateTimePicker Format property as Vivek said, this allow us to display the date/time in the specified format string within the DateTimePicker, then, it will be simple just as we do to get text from a TextBox.
We are now able to get Date only easily by getting the Text from the DateTimePicker:
NOTE: If you are planning to insert Date only data to a date column type in SQL, see this documentation related to the supported String Literal Formats for date. You can not insert a date in the format string ydm because is not supported:
the above code ends in the following Exception:
Be aware. Cheers.