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", "");
}
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"]))
};
{
RegisterClientScriptBlock("alert", "");
}
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"]))
};
Mageshwaran RPosted Nov 12, 2019, 6:44 AM
Apurva SinghPosted Sep 24, 2019, 1:22 AM
Jaimin ShethiyaPosted Sep 24, 2019, 1:03 AM
can you convert date in SQL side and after checked.
here is the example same as the your format
also refer this below links for other format in future and let me know if you have needed any other help.
Thanks
shankar naspuriPosted Sep 18, 2019, 8:29 AM
Abhay ShankerPosted Aug 3, 2015, 12:13 PM
string format = "dd/mm/yyyy";
DateTime dateTime = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture);
string strNewDate = dateTime.ToString("yyyy-dd-mm");
Rajeesh MenothPosted Aug 3, 2015, 8:37 AM
//Put thiz code
using System.Globalization;
Ref this : https://rajeeshmenoth.wordpress.com/2014/11/12/string-was-not-recognized-as-a-valid-datetime/DateTime From = DateTime.ParseExact(txtFrom.Text, "yyyy/mm/dd", CultureInfo.InvariantCulture);
Upendra Pratap ShahiPosted Aug 3, 2015, 8:24 AM
string DateString = "11/12/2009";
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime dateVal = DateTime.ParseExact(DateString, "yyyy-MM-dd", culture);
Amitesh VermaPosted Aug 3, 2015, 8:14 AM
IFormatProvider culture = new CultureInfo("en-US", true);