DateDiff Totals (1 Viewer)

Hek

Registered User.
Local time
Yesterday, 23:53
Joined
Oct 30, 2018
Messages
73
Hi all,

What im trying to do is sum all the results of multiple DateDiff's to find a total.
The only result i can get is all the datediff results all together one after the other in the same field (not added),I'm getting this result by adding the fields together in a query.
Any help would be greatly appreciated.

Regards
Hek
 

isladogs

MVP / VIP
Local time
Today, 07:53
Joined
Jan 14, 2017
Messages
18,247
So you're saying that you're adding e.g. 5+2+7 and getting 527 instead of 16?
If so you are concatenating text values rather than adding numbers

Can you post the code being used
 

Hek

Registered User.
Local time
Yesterday, 23:53
Joined
Oct 30, 2018
Messages
73
Thats exactly what is happening.
Is this what you mean when you're asking for code?
Total Time: [Picking Time]+[Fabrication Time]+[Finishing Time]+[Packing Time]
 

isladogs

MVP / VIP
Local time
Today, 07:53
Joined
Jan 14, 2017
Messages
18,247
I actually meant the underlying code in each of your DateDiff calculations

DateDiff returns a long integer value - so I'm trying to understand how you've got text for each item
Are the 4 items in [Picking Time]+[Fabrication Time]+[Finishing Time]+[Packing Time] text fields? Or variables defined as strings or as variants?
 

Hek

Registered User.
Local time
Yesterday, 23:53
Joined
Oct 30, 2018
Messages
73
Total Time(hrs): Format((DateDiff("n",[Picking Start Time],[Picking Finish Time]))/60,"Standard")

That is what im using for to get the total time for Picking, Fabrication, Finishing and Packing.
 

isladogs

MVP / VIP
Local time
Today, 07:53
Joined
Jan 14, 2017
Messages
18,247
That's your problem. Format converts all values into variant (text) strings.

Why do DateDiff in minutes ("n") then divide by 60?
If you want whole hours use "h"

BUT I suggest you sum the values in minutes (with no formatting)
THEN divide the total value by 60 to get hours if you wish

Why use Standard format? Do you want thousand separators? e.g. 2,500
 

Hek

Registered User.
Local time
Yesterday, 23:53
Joined
Oct 30, 2018
Messages
73
Thank you, after going back over it i don't know why i did either. i think the reason i used standard formatting was so i could divide it by 60. (very silly i know)

Edit: After I took the formatting out and calculations it worked a charm, thank you very much :)
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 07:53
Joined
Jan 14, 2017
Messages
18,247
Glad to have helped. Onwards & upwards ...
 

Users who are viewing this thread

Top Bottom