# Determine how many days a future date is from today vb 6

trying to determine how days a future date is from today and if less than a day return the hours
date format: 10/25/2016
###### Who is Participating?

x
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.

Problem resolverCommented:
You can use DateDiff like
``````Dim datTim1 As Date = #1/4/2001#
Dim datTim2 As Date = #1/9/2001#
' Assume Sunday is specified as first day of the week.
Dim wD As Long = DateDiff(DateInterval.Weekday, datTim1, datTim2)
Dim wY As Long = DateDiff(DateInterval.WeekOfYear, datTim1, datTim2)
``````
Older than dirtCommented:
Unless there's a time associated with the date there's no way to tell how many hours something is from now except in multiples of 24. But assuming you have the time then here's how you can tell.

BTW the code supplied by HuaMinChen is VB.Net and not VB6.

``````Dim dte1 As Date
Dim dte2 As Date
Dim dte3 As Date
Dim intDiff As Integer

' set up some test data
dte1 = Now
dte2 = DateAdd("h", 5, Now) ' Create a date 5 hours from now
dte3 = DateAdd("d", 2, Now) ' Create a date 2 days from now

' Test the dates
intDiff = DateDiff("H", dte1, dte2)
If intDiff < 24 Then
MsgBox "Difference is " & intDiff & " hours"
End If

intDiff = DateDiff("H", dte2, dte3)
If intDiff > 24 Then
intDiff = DateDiff("D", dte2, dte3)
MsgBox "Difference is " & intDiff & " days"
End If
``````

Experts Exchange Solution brought to you by

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

Author Commented:
Thanks , but i don't see how to check the date like 10/25/2016
Older than dirtCommented:
Now() is a date like yours except it also contains the time.

``````Dim dte1 As Date
Dim dte2 As Date
Dim intDiff As Integer

' set up some test data
dte1 = Now
dte2 = "10/25/2016"

' Test the dates
intDiff = DateDiff("H", dte1, dte2)
If intDiff < 24 Then
MsgBox "Difference is " & intDiff & " hours"
End If

intDiff = DateDiff("H", dte1, dte2)
If intDiff > 24 Then
intDiff = DateDiff("D", dte1, dte2)
MsgBox "Difference is " & intDiff & " days"
End If
``````
Author Commented:
Got it, thanks
###### 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.