且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从数据库中检索日期字段

更新时间:2023-02-08 17:01:07

日期和时间数据类型和函数 [ ^ ]



SQL Server DATEPART()函数 [ ^ ]


当您显示日期时,使用ToString将其转换为您选择的格式,这将消除时间格式。



dtDate。 ToString(dd-MMyyyy)



c#没有Date-only类型所以时间总是在那里。



https://msdn.microsoft.co m / en-us / library / system.web.ui.webcontrols.boundfield.dataformatstring(v = vs.100).aspx [ ^ ]


将DataGridView Column.DefaultCellStyle.Format设置为dd-MM-yyyy,它将为您完成所有操作。

https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle.format.aspx [ ^

Hi frds,
I save datetimepicker value(26-11-2015) in date field and retrieve this date in datagrid view cell.when i retrieve this fiels it show(26-11-2015 12:00 AM). But i want only in date format. how can i do this.
Thank you

Date and Time Data Types and Functions[^]

SQL Server DATEPART() Function[^]


When you show the date convert it to a format of your choice using ToString which eliminates the time format.

dtDate.ToString("dd-MMyyyy")

c# doesn't have a Date-only type so the time is always going to be there.

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring(v=vs.100).aspx[^]


Set the DataGridView Column.DefaultCellStyle.Format to "dd-MM-yyyy" and it will do it all for you.
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle.format.aspx[^]