Insert DateTime with ("yyyy-MM-dd " + _tbStartTime.Text + ":" + _tbStartMinute.Text + ":ss";

trying to insert datettime into db from asp.net code behind with same date, but different time like -->

Convert.ToDateTime(dtSAC.Rows[0]["starttime"].ToString("yyyy-MM-dd" + _tbStartTimeHour.Text + ":" + _tbStartTimeMinute.Text + ":ss"))

but its giving error , 'No overload for method 'ToString' takes 1 arguments
LVL 1
doramail05Asked:
Who is Participating?
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Maybe this work for you:
DateTime myDate = Convert.ToDateTime(dtSAC.Rows[0]["starttime"]).Date.AddHours(int.Parse(_tbStartTimeHour.Text)).AddMinutes(int.Parse(_tbStartTimeMinute.Text));

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
why not take the starttime field, which is datetime, and create a new datetime with the hour and minute?

DateTime starttime = (DateTime)dtSAC.Rows[0]["starttime"];
int hours = int.Parse(_tbStartTimeHour.Text );
int minutes = int.Parse(_tbStartTimeMinute.Text);
DateTime r = new Datetime(starttime.Year, starttime.Month, starttime.Day).AddHours(hours).AddMinutes(minutes);

Open in new window


untested code, might have typos ...
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Oops, It looks like angel solution :p
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
yup, except that I wrote, by practice, in several lines of code.
this is because I want to be able to know on which assignment the error actually occurs, if any.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.