How i convert date in yyyy/mm/dd

Aug 3 2015 8:12 AM

How i can Change my date into yyyy-mm-dd format and this From and to are parameters of SQL  Stored Procedure  .so please tell me what i do
 txt_from.Text='01/08/2015';
 txt_to.Text='03/08/2015';
 
 DateTime from = new DateTime(Convert.ToInt32(txt_from.Text.Split('/')[2]), Convert.ToInt32(txt_from.Text.Split('/')[1]), Convert.ToInt32(txt_from.Text.Split('/')[0]));
DateTime to = new DateTime(Convert.ToInt32(txt_to.Text.Split('/')[0]), Convert.ToInt32(txt_to.Text.Split('/')[1]), Convert.ToInt32(txt_to.Text.Split('/')[2]));
if (to > Convert.ToDateTime(DateTime.Now.ToShortDateString()))
{
RegisterClientScriptBlock("alert", "<script>alert('To date can not be later than current date.');</script>");
}
else
{
to = to.AddDays(1);
if (from <= to)
{
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@from",from),
new SqlParameter("@to",to),
new SqlParameter("@PortalId",Convert.ToInt32( Session["PortalId"]))

}; 


Answers (8)