Click here to Skip to main content
15,996,211 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.......
Posted

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[^]
 
Share this answer
 
Comments
Sandeep Mewara 24-Apr-12 11:47am    
My 5!
VJ Reddy 24-Apr-12 12:01pm    
Thank you, Sandeep.
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900