Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with DaysDiff/HourDiff (not really datediff())

perryche@yahoo.com
Guest
 
Posts: n/a
#1: Nov 13 '05
4 Fields:

Date1 Time1
Date2 Time2

How do I calculate days/hours diff between Date1Time1 & Date2Time2?

e.g. 3days 12hours

If it were 05/02/05 11pm and 05/03/05 8am? It should say 0day 9hrs.

If I have a bunch of these days/hrs diff, how do I come up with a
formulae to add them all up as well? I know if I do a sum(), I will
get a bunch of number again!

Thanks in advance.
Perry


Arno R
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Help with DaysDiff/HourDiff (not really datediff())


Perry,
Maybe you need to do something like the following:

First you will need to combine the fields Datex and Timex.
I don't know how your dates and times are formatted but as long as they are *real*
date,time fields you can convert them to long and just add the values.
So DateTime1= Clng(Date1) + Clng(Time1)
DateTime2= Clng(Date2) + Clng(Time2)
Then you can do a Datediff to count the hours. You can add the hours as you wish.
HoursDiff = DateDiff("h", DateTime1, DateTime2)
Your Result will be like CalcResult: HoursDiff \24 & " days " & HoursDiff Mod 24 & " hrs"

--
Hope this helps
Arno R



<perryche@yahoo.com> schreef in bericht
news:1109870383.066066.25880@f14g2000cwb.googlegro ups.com...[color=blue]
>4 Fields:
>
> Date1 Time1
> Date2 Time2
>
> How do I calculate days/hours diff between Date1Time1 & Date2Time2?
>
> e.g. 3days 12hours
>
> If it were 05/02/05 11pm and 05/03/05 8am? It should say 0day 9hrs.
>
> If I have a bunch of these days/hrs diff, how do I come up with a
> formulae to add them all up as well? I know if I do a sum(), I will
> get a bunch of number again!
>
> Thanks in advance.
> Perry
>[/color]




Arno R
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Help with DaysDiff/HourDiff (not really datediff())


Oops! Obviously I was a bit to fast with this ....

So DateTime1= Clng(Date1) + Clng(Time1)
DateTime2= Clng(Date2) + Clng(Time2)
Should read:
So DateTime1= Clng(Date1) + Cdbl(Time1)
DateTime2= Clng(Date2) + Cdbl(Time2)

Arno R


"Arno R" <arracomn_o_s_p_a_m@tiscali.nl> schreef in bericht
news:42275dc3$0$44087$5fc3050@dreader2.news.tiscal i.nl...[color=blue]
> Perry,
> Maybe you need to do something like the following:
>
> First you will need to combine the fields Datex and Timex.
> I don't know how your dates and times are formatted but as long as they are *real*
> date,time fields you can convert them to long and just add the values.
> So DateTime1= Clng(Date1) + Clng(Time1)
> DateTime2= Clng(Date2) + Clng(Time2)
> Then you can do a Datediff to count the hours. You can add the hours as you wish.
> HoursDiff = DateDiff("h", DateTime1, DateTime2)
> Your Result will be like CalcResult: HoursDiff \24 & " days " & HoursDiff Mod 24 & "
> hrs"
>
> --
> Hope this helps
> Arno R
>
>
>
> <perryche@yahoo.com> schreef in bericht
> news:1109870383.066066.25880@f14g2000cwb.googlegro ups.com...[color=green]
>>4 Fields:
>>
>> Date1 Time1
>> Date2 Time2
>>
>> How do I calculate days/hours diff between Date1Time1 & Date2Time2?
>>
>> e.g. 3days 12hours
>>
>> If it were 05/02/05 11pm and 05/03/05 8am? It should say 0day 9hrs.
>>
>> If I have a bunch of these days/hrs diff, how do I come up with a
>> formulae to add them all up as well? I know if I do a sum(), I will
>> get a bunch of number again!
>>
>> Thanks in advance.
>> Perry
>>[/color]
>
>
>
>[/color]




Perry Cheng
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Help with DaysDiff/HourDiff (not really datediff())


Arno, thanks. I will give it a try tomorrow.

Perry



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Perry Cheng
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Help with DaysDiff/HourDiff (not really datediff())


Arno,
Thanks, your suggestions worked perfectly.

Perry



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Closed Thread