Add time and date from two dtp DateTimePickers [RESOLVED]
I have two dtps on a form, one is set up for a date, the other is set up as "HH:mm" for a time. I need to combine the two values into a single string for insertion into a database.
What is the easiest way of doing this?
My problem is that I'm getting the time and date from the second dtp when I only want the time.
Re: Add time and date from two dtp DateTimePickers
Use the Format function to format each dtp's value. Then concatinate them together.
Re: Add time and date from two dtp DateTimePickers
VB Code:
[FONT=Courier New]
Private Sub Form_Load()
Dim mDate As Date
mDate = CDate(Format(DTPicker1, "dd/mm/yy") & Format(DTPicker2, " hh:mm"))
MsgBox mDate
End Sub[/FONT]
DTPIcker1 has date value and DTPicker2 has time value and in the combination of the both, you will get the result in mDate variable which can be inserted in database.
Re: Add time and date from two dtp DateTimePickers
Another option. Set the Time of the first date picker from the second beforehand.
VB Code:
dtp1.Hour = dtp2.Hour
dtp1.Minute = dtp2.Minute
dtp1.Second = dtp2.Second
msgbox Format$(dtp1.Value,"dd-MMM-yyyy hh:mm:ss")