Here i discussing about the date casting.
When i fetching data from database, then i found that a date column DateTime both. But i want display only date from that datetime.
For this solution i am using below code:
//Create a Datatable
DataTable dtEmp = new DataTable();
dtEmp = objEmployee.GetData(); //Datatable is fill.
lblDOB.Text = dtEmp.Rows[0]["DOB"]).ToString();
Here output show like : 10/04/1991 12:00:00
But i want show only Date not time. for that follow below code:
//Create a Datatable
DataTable dtEmp = new DataTable();
dtEmp = objEmployee.GetData(); //Datatable is fill.
lblDOB.Text = Convert.ToDateTime(dtEmp.Rows[0]["DOB"]).ToShortDateString();
Here output show like : 10/04/1991
Here this is done casting in ToDateTime to ToShortDateString().
Conversion Conversion Emoticon Emoticon