I have a table which stores dates of an event.I display the dates in a few labels.Everything works fine.BUT i want to display my dates in the format 'dd-mm-yyyy' and the date is stored in sql server as 'mm/dd/yyyy'.
Create table testDate
(
EventStart date
EventEnd date
)
The dates come from datepicker and i dont want to format my dates in datepicker because it gives me conversion problems. I want to change the format when i display the date in asp.net Label. Right now i dsiplay the date as below :
string CS = ConfigurationManager.ConnectionStrings["SportsActiveConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from testdate", con);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
DateTime Received;
DateTime.TryParse(rdr["EventStart"].ToString(),CultureInfo.InvariantCulture,DateTimeStyles.None, out Received);
Label1.Text = Received.ToShortDateString();
}
}
}
Thanks in advance.