Hi,
I have one requirement to display only the Date part of a DateTime column in datagrid.
My DateTime column may contain null values also.
My concern is while inserting the value into the table ,I am using it as
DateTime.Now.Date but it stores the values as "29/08/2007 00:00:00".
I only want 29/08/2007 in my datagrid.
How to do that?If I can insert 29/08/2007 only ,it will also help me.
Please suggest
You have a few options.
1. You can insert only the date into the database by using DateTime.Now.ToShortDateString().
2. You can insert the date as you are and use String.Format to control how the date will be displayed in your datagrid. You will need to add an TemplateColumn and ItemTemplate in your datagrid. Use a label control in your ItemTemplate to hold the date.
Example.
string date = "29/08/2007"; //replace this with the row/column value returned to your dataset.
Label1.Text = String.Format("{0:dd/MM/yyyy}", date);
Either way should work for you.
Nathan