subtracting dates

If i have two dates and times - how can i work out the time between them.

ie I would like to know if it has been over 24 hours between 2 specified dates and times.
wormboy__6Asked:
Who is Participating?
 
HennyConnect With a Mentor Commented:
Hi wormboy_6, try this

Dim date1 As Date
Dim date2 As Date
Dim lSeconds As Long
Dim lHours As Long
Dim lMins As Long
Dim lDays As Long
           
date1 = CDate("August 29, 1999 12:20:55PM")
date2 = CDate("August 30, 1999 1:54:12PM")
lSeconds = CStr(DateDiff("s", date1, date2))


lDays = lSeconds \ (24& * 3600)
lSeconds = lSeconds - lDays * 24& * 3600
lHours = lSeconds \ 3600
lSeconds = lSeconds - lHours * 3600&
lMins = lSeconds \ 60&
lSeconds = lSeconds - lMins * 60
0
 
DrDelphiCommented:
Look at the DateDiff Function...


Good luck!!
0
 
RuchiCommented:
I did not understand your problem but this might help you..

Dim Date1 As Date
Dim Date2 As Date
Dim date3 As Integer

Date1 = "1999/12/25"
Date2 = "2005/01/03"

date3 = DateDiff("d", Date1, Date2)

MsgBox date3

If you want to combine date and time text

datettime = CDate(txtDate & " " & txtTime)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DrDelphiCommented:
Hmmmmm..... looks like something I might have suggested....<g>
0
 
AxterCommented:
Henny
You have the right answer, but I think you made it a little more difficult then it had to be.  He/She only needs the hour difference.

Dim TheHourDiff As Integer
Dim date1 As Date
Dim date2 As Date
date1 = CDate("August 29, 1999 12:20:55PM")
date2 = CDate("August 30, 1999 1:54:12PM")
TheHourDiff = DateDiff("h", date1, date2)
0
 
wormboy__6Author Commented:
cheers
0
All Courses

From novice to tech pro — start learning today.