0

Dataset value Convert DateTime to Date

   foreach (DataRow dr in dataSet.Tables[0].Rows)
   {
      dr["JoinDate"] = DateTime.Parse((dr["JoinDate"].ToString())).ToShortDateString();
      dataSet.Tables[0].Rows[0]["JoinDate"] = dr["JoinDate"];
   }
Ajay
  • 6,418
  • 18
  • 79
  • 130
bhargav
  • 13
  • 1
  • 7

2 Answers2

0

I assume that you want to get the Date part alone form Datetime from your question (datetime is should change to only date in dataset)

foreach (DataRow dr in dataSet.Tables[0].Rows)
            {
                dr["JoinDate"] = DateTime.Parse((dr["JoinDate"].ToString())).Date
                dataSet.Tables[0].Rows[0]["JoinDate"] = dr["JoinDate"];
            }

Datetime.Date will give you the date value.

refer this : How to remove time portion of date in C# in DateTime object only?

Community
  • 1
  • 1
backtrack
  • 7,996
  • 5
  • 52
  • 99
0

Try this

foreach (DataRow dr in dataSet.Tables[0].Rows)
{
  dr["JoinDate"] = dr["JoinDate"].ToString("dd/MM/yyyy");
  dataSet.Tables[0].Rows[0]["JoinDate"] = dr["JoinDate"];
}
Ajay
  • 6,418
  • 18
  • 79
  • 130