How to convert India Standard Time to SQL DataTime in C#

Last Reply on Dec 07, 2016 05:41 AM By revathip

Posted on Dec 07, 2016 04:41 AM

I created startdate column with datetime datatype in sql.

I'm storing this startdate value to array of string.for example

 string[] Param = parameters;

how to convert this startdate from string to datetime.

can anyone help me

Results 1 - 5 of 6 12
Posted on Dec 07, 2016 04:43 AM

Hi revathip,

 Refer the below code sample.

string[] Param = { DateTime.Now.ToString(), "2016/12/07" };
DateTime date1 = Convert.ToDateTime(Param[0]); // 12/7/2016 5:04:41 PM
DateTime date2 = Convert.ToDateTime(Param[1]); // 12/7/2016 12:00:00 AM

 


Posted on Dec 07, 2016 04:56 AM

when i convert like this,

       DateTime startdate = Convert.ToDateTime(Param[5]);

it shows the following error,

string was not recognized as a valid DateTime


Posted on Dec 07, 2016 04:58 AM
revathip says:
Param[5]

 provide the data in param[5]


Posted on Dec 07, 2016 05:03 AM

"Wed Dec 07 2016 00:00:00 GMT+0530 (India Standard Time)"


Posted on Dec 07, 2016 05:14 AM

Hi revathip,

Refer the below code.

string[] Param = { DateTime.Now.ToString(), "2016/12/07", "2016/12/06", "2016/12/05", "2016/12/04", "Wed Dec 07 2016 00:00:00 GMT+0530 (India Standard Time)"};
DateTime date = DateTimeOffset.ParseExact(Param[5], "ddd MMM dd yyyy HH:mm:ss 'GMT'zzz '(India Standard Time)'", System.Globalization.CultureInfo.InvariantCulture).Date;