Post

2 followers Follow
0
Avatar

Displaying hours and minutes from dates

Hi,

 

I would like to calculate the hours and minutes between these two dates, but displaying it with a conditional; if hours is less than 1 display it in minutes, if it is equal or more than one, displays it in hours and minutes.

 

I have try this, but I do not know how to include the conditional:

 

var ini = moment(@Fecha de entrega solicitada);
var fin = moment(@Fecha inicio solicitada);
var dur = moment.duration(ini.diff(fin));
var hora = dur.asHours();
var minutos = Math.round(dur % 60);


hora + " hora" + " " + minutos +" minutos"

 

Regards,

Ivan Morales

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Ivan,

var ini = moment(@Fecha de entrega solicitada); 
var fin = moment(@Fecha inicio solicitada); 
var diffMin = fin.diff(ini,"m");
var hora = parseInt(diffMin/60);
var minutos = diffMin % 60;
hora > 0 ? hora + " hora" + " " + minutos + " minutos" : minutos + " minutos"

Rainer

 

 

Rainer Grabowski 0 votes
Comment actions Permalink