B M Suchitra

B M Suchitra

  • NA
  • 507
  • 418.1k

Problem converting string to datetime format

Jan 9 2012 3:58 AM
Hi,

I am using calender extender for 2 textboxes allowing user to enter start and end date.. The format is "dd/MM/yyyy".. My code is as below for converting to datetime..

 private int duration(string startdate, string enddate)
    {

        DateTime dt1= DateTime.Parse(startdate);
        DateTime dt2= DateTime.Parse(enddate);
        //dt1 = Convert.ToDateTime(txtstartdate.Text);
        //dt2 = Convert.ToDateTime(txtenddate.Text);
        TimeSpan ts = dt2.Subtract(dt1);
        int days = ts.Days;
        Session["days"] = days.ToString();
        return days;
    }
    protected void txtenddate_TextChanged(object sender, EventArgs e)
    {
       int projectdays = duration(txtstartdate.Text, txtenddate.Text);

        txtduration.Text = Convert.ToString(projectdays);
    }
==================
When user selects the date from calender extender say todays date.9/1/2012
it is been taken as 1 september 2012

Answers (15)