Formatting DateDiff hh:nn:ss (1 Viewer)

jpl458

Well-known member
Local time
Today, 08:05
Joined
Mar 30, 2012
Messages
1,038
I have the following expression in a query in the QBE grid:

Code:
Dur:  Format ( DateDiff ("s", [TimeValue(dteCreated]), [TimeValue(dteModified]),  hh:nn:ss" ) AS HH_NN_SS

Trying to calc the duration between 2 times;

Get this error

1674321653747.png

It must be something I am overlooking, but I can't see it.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:05
Joined
Oct 29, 2018
Messages
21,474
Did you forget the opening quotes for the second Format argument?

Also, don't think you need the "AS" part.
 

plog

Banishment Pending
Local time
Today, 10:05
Joined
May 11, 2011
Messages
11,646
4 left parenthesis, 3 right.
 

ebs17

Well-known member
Local time
Today, 17:05
Joined
Feb 7, 2020
Messages
1,949
The process is unclear. Seconds (from the difference) cannot be converted directly into the format used.
Code:
Format(dteModified - dteCreated, "hh:nn:ss")
... shows times less than 24 hours.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2002
Messages
43,295
Your parenthes and square brackets are mixed up.
Dur: Format ( DateDiff ("s", [TimeValue(dteCreated]), [TimeValue(dteModified]), hh:nn:ss" ) AS HH_NN_SS

Dur: Format ( DateDiff ("s", TimeValue([dteCreated]), TimeValue([dteModified]), "hh:nn:ss" ) AS HH_NN_SS

That is syntactically correct but it doesn't work since the datediff() won't return a formatted string. It returns seconds as you have used it. You need to create your own custom function which takes in seconds and returns a string formatted as hh:nn:ss
 

ebs17

Well-known member
Local time
Today, 17:05
Joined
Feb 7, 2020
Messages
1,949
... whereby the question arises why one should take a detour via seconds if one wants to have an entry in hh:nn:ss.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:05
Joined
Feb 19, 2002
Messages
43,295
The OP is calculating the difference between two times. The DateDiff() does NOT return the result in the desired format. That is why.
 

Users who are viewing this thread

Top Bottom