Search code examples
asp.netdatetime-format3-tiercalendarextender

Have kept format of ajaxcalendar control as "dd/mm/yyyy" and want to save in database as mm/dd/yyyy


I m using ajax calendar control to a textbox, have set its format as "dd/mm/yyyy" .

  Bapur.Date = txtdate.Text;

in data access layer

 cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = bapur.Date;

on saving, like above ( where Date is a string Bapur is object of businesslayer class) in the database where datatable in database has date as datetime format. m getting an error : cant convert string to datetime i dint get error when format was "mm/dd/yyyy" .

Basically, I want users to view date in dd/mm/yyyy but on saving i want it in

mm/dd/yyyy

Have tried a lot but not working.

here is my answer ---- https://stackoverflow.com/a/11720162/1445836 -----


Solution

  • got my answer

                string old = txtdate.Text;
                string newDate = DateTime.ParseExact(old, "dd/MM/yyyy", null).ToString("MM/dd/yyyy");
    
                Bapur.Date = newDate.ToString();