combine different date and time using two datetimepickers

sid

Member
Joined
Sep 16, 2011
Messages
13
Programming Experience
Beginner
hi friends,
i have two datetimepickers in a window form application.One datetimepicker is used to select date and second one is for time.
Now i want to combine date from DTP1 and time from DTP2 and update the database with the selected combined datetime value using vb.net.
Thankyou
 
The Value property of the DateTimepicker returns a DateTime value. The Date property of a DateTime will return another DateTime containing just the date part, i.e. the time part is zeroed, and the TimeOfDay property returns a TimeSpan containing just the time part. Get one from one and the other from the other and then add them together... voila!
 
The Value property of the DateTimepicker returns a DateTime value. The Date property of a DateTime will return another DateTime containing just the date part, i.e. the time part is zeroed, and the TimeOfDay property returns a TimeSpan containing just the time part. Get one from one and the other from the other and then add them together... voila!

plz explain me...what i have done is...
VB.NET:
Try
Dim strdatetime As String = DateTimePicker1.Text + " " + DateTimePicker2.Text
            Dim date1 As Date = Date.Parse(strdatetime, System.Globalization.CultureInfo.InvariantCulture)
  sqlupdate1 = "UPDATE paper SET date='" & date1.ToString & "' WHERE paperid='" + dgvPaper.CurrentRow.Cells("paperid").Value + "'"
                Dim cmd3 As New SqlCommand(sqlupdate1, con)
                cmd3.ExecuteNonQuery()
Catch err As System.Exception
            MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
here when i update i get error "string is not recognized as valid datetime" only in case when i select date greater than 12 from datetimpicker1 otherwise its working fine.
i have taken short format of datetimepicker1 and time format for dtp2..
 
That is absolutely nothing like what I said. I would say that you haven't even read my post. The very first sentence says:
The Value property of the DateTimepicker returns a DateTime value.
and nowhere in your code do I see you using that property. When I answer questions I will tell people to use certain properties and/or methods and I expect that they will know what a property or a method is and how to use one in general terms. I've told you what properties to use and I expect you to be able to use them. If you don't understand what properties and methods are then you probably shouldn't even be here asking that question. You should be working your way through a beginners tutorial that explains basic things like what properties and methods are and how to use them. Here is an example of such a tutorial:

Microsoft Visual Basic .NET tutorials for Beginners

If you do already know how to use properties then please read what I posted and follow the instructions.
 
Back
Top