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

Posted on 2011-10-13
Last Modified: 2012-05-12
trying to insert datettime into db from 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
Question by:doramail05
    LVL 142

    Expert Comment

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

    Accepted Solution

    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

    LVL 17

    Expert Comment

    by:Carlos Villegas
    Oops, It looks like angel solution :p
    LVL 142

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now