Duration Field x hh:mm format
AnsweredHello, guys,
I am calculating the difference between two dates using moments#diff. As a result I am getting a hh:mm format just like I wanted. Now I want to subtract a "Duration field" from that hh:mm time. The problem I am facing is that a Duration field returns a number (i.e.: 1.456) so I believe I can't use diff again. Is there a simple way to parse number to hh:mm or something like this?
You can see below the code that is working right now without the subtraction.
Thanks,
Eduardo
a = moment(Período Inicial).tz("America/Sao_Paulo");
b = moment(Período Final).tz("America/Sao_Paulo");
t1 = moment(a, "hh:mm");
t2 = moment(b, "hh:mm");
t3 = moment(t2.diff(t1)).format("hh:mm")
// Now I need to subtract @Almoço (which returns a duration such as 1.456) from t3...
-
Hi Rainer,
Yes, you got it right as per the t3 variable.
When you create a "Duration" field for a Podio app item it lets you enter with hours, minutes and seconds. But when you call that field within a "Calculation" field with the "@" it becomes a float (i.e.: 1.50 instead of 1:30).
As my t3 variable is using the hh:mm format I cannot subtract the "Duration" field from it. I don't know why Podio handles "Duration" fields that way instead of simply using the hh:mm:ss format as "Date" fields do.
Have I made myself clear?
Thanks,
Eduardo
-
This should work:
var a = moment(Período Inicial).tz("America/SaoPaulo");
var b = moment(Período Final).tz("America/SaoPaulo");
var t1 = moment(a, "hh:mm");
var t2 = moment(b, "hh:mm");
var tDur = parseFloat(@duration field);
var t3 = moment(t2.diff(t1)).subtract(tDur, "hours").format("hh:mm");
t3Rainer
-
Hi guys,
Is there any way just to display a real duration field in another app in hh:mm format by using a calculation field?
This is what I would like to achieve:
- I have an app A with a duration field (Podio duration field in hours and minutes)
- I have an app B with a relation to app A. I would like to show the duration field there in the same format as the input format, being "HH: MM". Now 5 hours and 10 minutes displays as 5,16666666667 instead of 5:10.
It seems so simple, but apparently it is not.
I hope you guys understand what I am trying to explain here. Thanks a lot for any help in advance. :)
Casper
-
Hi Casper,
here I've explained the way. You've to modify the code a bit to:
var asMin= @sum of Duration*60;
var hrs = parseInt(asMin/60);
var min = Math.round(asMin % 60);
hrs + ":" + minHope that helps,
Rainer
Please sign in to leave a comment.
Comments
8 comments