?
Solved

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

Posted on 2011-10-13
4
Medium Priority
?
278 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:doramail05
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36962661
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
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 2000 total points
ID: 36962712
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
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 36962733
Oops, It looks like angel solution :p
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36966904
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question