Format hours, minutes and seconds

Hi, guys!

I have three variables where I store three values:

. Hours = DiffHours(startDate, endDate);

. Minutes = DiffMinutes(startDate, endDate);

. Seconds = DiffSeconds(startDate, endDate);

Counting is working well. However, when it gets bigger than 60, the minutes are increased, but seconds keep growing, and the same happens to the relation Hour-Minute.

Here's an example:

Hope I've been clear enough so that you can help me.


Best regards,

Eduardo Coelho

Hi Eduardo,

could you please share little more details that how you maintain the relation between minutes, seconds and hours.

Hi,

It's because de diff returns the diference bettween two numbers:

eg. diffminuts

Returns the difference in minutes between 'dt1' and 'dt2'; i.e. how many minutes have passed between these two dates:

  • Returns a positive number if 'dt1' is smaller than 'dt2';
  • Returns a negative number if 'dt1' is bigger than 'dt2'.
  • Returns 0 if the two dates are equal.

(from https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Date_and_Time#DiffMinutes)


If you need date time ( the two dates could have days of diference) the best solution is to separate all the components in difrent variables (ex: years; months; days;... ) you can create a structure to store that info.

After that if you need to show the diference you simply show year+"-"+month+...

if you need to use this diference to add in other date time variable you just add them separatly addyear(newdate, year) addmonth (newdate,month)...

if you ned to get those values you do something like this

get the diference =DiffSeconds( datetime1, datetime2)  
secunds = mod (diference ,60)
diference = trunc(diference/60)
minutes = mod(diference,60)
diference = trunc(diference/60)
hours = mod(diference,24)
diference = trunc(diference/24)
...
or  you can add the diference to a null date, and when you need the values you use
year(date)-year(nulldate())
month(date) - month(nulldate())
...

hope that this helped


You can try something like this:

NewTime(
    If( DiffMinutes(date time start,date time end) > 60,DiffHours(date time start,date time end),0) ,
Mod(DiffMinutes(date time start,date time end),60),0)


Nuno Miguel Verdasca wrote:

You can try something like this:

NewTime(
    If( DiffMinutes(date time start,date time end) > 60,DiffHours(date time start,date time end),0) ,
Mod(DiffMinutes(date time start,date time end),60),0)


Hi, Guys, thanks for fast replying.

Nuno, I've already tryed something like you suggested.

That's what I've done so far:

When I tried the NewTime(If ...), but don't know for sure how to use the If statement inside the expression field.

Should I make a NewTime(...) for each part? I mean, a NewTime(...) for Hours, another for Minutes...

Another question: in the If statement example you posted there are 3 conditions, I guess. How do I make it? The first condition is before the comma and the second after it? In this case, with 3 conditions, I'm confused.


Sorry for so many questions.


Hi,

There are several components in the Forge with countdown timers from which you can check how they are implemented. Just revert the counting.

Search in Forge on countdown you find web and mobile versions.

Regards,

Daniel

Daniël Kuhlmann wrote:

Hi,

There are several components in the Forge with countdown timers from which you can check how they are implemented. Just revert the counting.

Search in Forge on countdown you find web and mobile versions.

Regards,

Daniel

Hi, Daniel,

Before doing it, I've searched a lot on Forge. There was just countdown elements, but I needed something that could "count up", or there was only non stable versions, so I've had this idea. But thanks.


Regards,

Eduardo Coelho


Eduardo Coelho wrote:

Nuno Miguel Verdasca wrote:

You can try something like this:

NewTime(
    If( DiffMinutes(date time start,date time end) > 60,DiffHours(date time start,date time end),0) ,
Mod(DiffMinutes(date time start,date time end),60),0)


Hi, Guys, thanks for fast replying.

Nuno, I've already tryed something like you suggested.

That's what I've done so far:

When I tried the NewTime(If ...), but don't know for sure how to use the If statement inside the expression field.

Should I make a NewTime(...) for each part? I mean, a NewTime(...) for Hours, another for Minutes...

Another question: in the If statement example you posted there are 3 conditions, I guess. How do I make it? The first condition is before the comma and the second after it? In this case, with 3 conditions, I'm confused.


Sorry for so many questions.


Hi Eduardo,

can you try something like this:

NewTime(If( DiffMinutes(ConsultaTable.List.Current.Atendimento.dtHoraInicio,ConsultaTable.List.Current.Atendimento.dtHoraTermino) > 60,Trunc(DiffMinutes(ConsultaTable.List.Current.Atendimento.dtHoraInicio,ConsultaTable.List.Current.Atendimento.dtHoraTermino)/60),0) ,
Mod(DiffMinutes(ConsultaTable.List.Current.Atendimento.dtHoraInicio,ConsultaTable.List.Current.Atendimento.dtHoraTermino),60),0)


Solution

If your difference is 68 seconds, DiffHours will say 0 (0 full hours), DiffMinutes will say 1 (one full minute) and DiffSeconds will say 68 (68 seconds). You don't get a smart "1 minute and 8 seconds".


What you can do is truncate those numbers

Hours = DiffHours(startDate, endDate);

Minutes = mod(DiffMinutes(startDate, endDate),60);

Seconds = mod(DiffSeconds(startDate, endDate),60);

This will return minutes without hours and seconds without minutes.


Solution

Thank you, everyone for the ideas and the replying!

For now the one that I marked as solution was the most simple and fitted the situation. But I will also study the others.


Best regards,

Eduardo Coelho