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.
- 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
- DateTime aDate = Convert.ToDateTime(dt.Rows[0][“ArrivalDate”]);
- txtArrivalDate.Text = aDate.ToString(“dd/MM/yyyy”);