将数据表中的Datetime列转换为Date数据类型列 [英] Converting of Datetime column to Date Datatype Column in a Data Table

查看:343
本文介绍了将数据表中的Datetime列转换为Date数据类型列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在用C#将datetime转换为日期格式时感到麻烦.
在这里,我以编程方式创建了一个数据表,并且还添加了列.但是我想要一列作为日期列.但是在C#中,我们只有日期时间方法.

这是我创建的数据表,..
DataTable dt = new DataTable();
dt.Clear();
dt.Columns.Add("DDBookID",typeof(System.Int32));
dt.Columns.Add("DDDate",typeof(System.DateTime));
dt.Columns.Add("Amount",typeof(System.Decimal));
dt.Columns.Add("CRTE_TS",typeof(System.DateTime));

对于DDDate列,我只需要Date数据类型. 任何人都可以帮忙解决这个问题...

在此先感谢.......

Hi,

I am troubling in a converting datetime to date format in C#.
Here i had created a datatable programatically and added columns also. But i want one column as a date column. But in C# we are having only datetime Method.

This is the Data table i had created,..
DataTable dt = new DataTable();
dt.Clear();
dt.Columns.Add("DDBookID", typeof(System.Int32));
dt.Columns.Add("DDDate", typeof(System.DateTime));
dt.Columns.Add("Amount", typeof(System.Decimal));
dt.Columns.Add("CRTE_TS", typeof(System.DateTime));

For DDDate column i want only Date Datatype..
Can any one help on this issue...

thanks in advance.......

推荐答案

据我所知,C#中没有仅Date 数据类型.因此,数据类型可以设置为DateTime 并在UI中显示时,例如. DataGridViewDataGrid 等,并且要在报告中打印,只能使用此处给出的所需格式打印Date 部分
http://msdn.microsoft.com/en-us/library/az4se3k1 (v = vs.71).aspx [ http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ]
As far as I know there is no Date only data type in C#. So, the Data type can be set as DateTime and while displaying in the UI eg. DataGridView, DataGrid etc. and for printing in reports, only Date part can be printed using the required format as given here
http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.71).aspx[^]
and
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]


您可以将此列添加为字符串.

如果将此列添加为strin,则可以灵活地添加日期格式.

然后在数据表中插入日期,您可以将日期时间转换为日期.
you Can add this column as string.

If you add this column as strin you will have flexiblty to add format of date.

And inserting date in datatable you can convert the datetime to date.


这篇关于将数据表中的Datetime列转换为Date数据类型列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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