Question

I am working in an application built in .NET framework 2.0 but I am running it in .NET framework 4.0, with SQL server as a database.

when I try to take date as a input from Calendar controller (Webforms) its in the format dd/MM/yyyy and this application using Convert.ToDateTime() to parse this date and it throws exception.

so how can I resolve this problem and is there any way that DateTime class object store the date in specific format means I want to store date in dd/MM/yyyy format even when I copy this date object to another, then both object should have same format.

and sorry for My English :p

Was it helpful?

Solution

Assuming you mean this Calendar control, you should just use the SelectedDate or SelectedDates property - let the control handle the conversions.

In general, you should avoid performing textual conversions unless you really need to. (This includes when you interact with the database - use parameterized SQL, and simply pass the DateTime values in the parameters.)

OTHER TIPS

var result = DateTime.ParseExact("29/01/2014", "dd/MM/yyyy", CultureInfo.InvariantCulture);

You should avoid converting DateTime to string and back if you can help it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top