Subtract date using datepickers

Initially i wanted to subtract dates from texboxes. i got the solution. The code is below but with textboxes in place of datepickers. now i want to use date pickers. how can the code be modified or how can i achieve that?
If i try to use this

Private Sub Command3_Click()
Dim DateA As Date, DateB As Date

DateA = CDate(DTPicker1 & " " & DTPicker3)
DateB = CDate(DTPicker2 & " " & DTPicker4)

mins = DateDiff("n", DateA, DateB)
MsgBox "mins = " & mins

i get a type mismatch
where DTPicker 1 and 2 contain dates
and 3 and 4 contain time. What can i do ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:
Hi asans,
    I am not sure why you are having two controls... one for date and another for time.
    Right Click DTPicker1 and Goto Properties. Select Format as "3 - dtpCustom" and in the Custom Format textbox, put      dd/MM/yyyy hh:mm:ss
    Click OK. Now you don't want DTPicker2 at all. Similarly do the same for DTPicker3 and delete 4. Now rename DTP3 to DTP2
    mins = DateDiff("n", DTPicker1, DTPicker3)
    will give you the result

Harisha M GEngineerCommented:
    If you still want to use 2 DTPs then use

    DateA = DTPicker1 + DTPicker2 - Int(DTPicker2)
    DateB = DTPicker3 + DTPicker4 - Int(DTPicker4)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you want to use 2 dtpickers for each date try this:

Dim DateA as string, DateB as string

DateA = format(DTPicker1.value,"DD MMM YYYY") & " " & format(DTPicker2.value,"HH:MM:SS")
Same with DateB
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

You can just subtrat dates:

DateA =DTPicker1.value - DTPicker2.value

The result will be a double with the whole numbers representing days and the fractional part of the answer represents the proportion of a day. e.g. If a value if 1.5 is returned the difference is 1.5 days or 36 hours.
Harisha M GEngineerCommented:
JR2003, that won't work :)
My dear friend,

Date picker holds both date and time, so you need to extract date as separate and time as separate,

i am giving example try this.....

Private Sub Command3_Click()
Dim DateA As Date, DateB As Date

DateA = CDate(format(DTPicker1,"MMM/dd/yyyy") & " " & format(DTPicker3,"hh:mm:ss"))
DateB = CDate(format(DTPicker2,"MMM/dd/yyyy") & " " & format(DTPicker4,"hh:mm:ss"))

mins = DateDiff("n", DateA, DateB)
MsgBox "mins = " & mins

even i answered this in
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.