如何从数据库中检索日期字段 [英] How to retrieve the date field from database

查看:119
本文介绍了如何从数据库中检索日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨frds,

我在date字段中保存datetimepicker值(26-11-2015)并在datagrid视图cell中检索这个日期。当我检索这个fiels时显示它(26-11-2015) 12:00 AM)。但我只想要日期格式。我怎样才能做到这一点。

谢谢

解决方案

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



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[^]


这篇关于如何从数据库中检索日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆