DateTime Conversion issue with C# in ASP.NET

a. String to DateTime Format

Suppose in database I have declared some field as DateTime then I have to pass the input as DateTime only.

  1. objBE.DeliveredDate = DateTime.ParseExact(txtDeliveredDate.Text, “dd/MM/yyyy”, null);   

Note: Here objBE.DeliveredDate field is DateTime which have been declared in BE layer.

b. DateTime to String Format

Supposed if we have to fetch the date from database and to display on Textbox then obviously we have to convert into string format. So we can do like this

  1. DateTime aDate = Convert.ToDateTime(dt.Rows[0][“ArrivalDate”]);    
  2. txtArrivalDate.Text = aDate.ToString(“dd/MM/yyyy”);