Converting hours to days, hours, minutes | Community
Skip to main content
New Participant
Feb 19, 2020 1:17 AM UTC
Solved

Converting hours to days, hours, minutes

Probably a simple script for some of you veterans, but as a rookie, I’m stumped. Could someone help with converting hours to days, hours and minutes (e.g., 619 hours = xx days, xx hours and xx minutes)? FormCalc or Javascript. Thanx in advance.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Nirmal_Jose
Nirmal_JoseAccepted solution
Employee
Feb 20, 2020 10:31 PM UTC

I know its a slight overkill and may not support your exact requirement, but AEM has an OOTB library that can help you with any date conversion. - moment.js

Moment JS can be found at [1], category name 'moment'

You can use various conversions as mentioned in [2]

 

[1] - /libs/clientlibs/granite/moment 

[2] - https://momentjs.com/docs/#/get-set/minute/

4 replies

New Participant
Aug 15, 2022 3:12 PM UTC

Could someone help with displaying the duration between two different dates and times in hours, and days and hours, if possible? I've reviewed almost every post related to this subject in the forums and tried virtually every recommendation out there, but I can't figure it out. Here's the form if anyone can assist. Date and time duration. Thank you in advance. 

Translate
Nirmal_Jose
Nirmal_JoseAccepted solution
Employee
Feb 20, 2020 10:31 PM UTC

I know its a slight overkill and may not support your exact requirement, but AEM has an OOTB library that can help you with any date conversion. - moment.js

Moment JS can be found at [1], category name 'moment'

You can use various conversions as mentioned in [2]

 

[1] - /libs/clientlibs/granite/moment 

[2] - https://momentjs.com/docs/#/get-set/minute/

Translate
Suraj_Kamdi
New Participant
Feb 19, 2020 7:11 AM UTC

@daniel_claire If I am correct... You can try with following js code

 

var days = Math.floor(providedHrs/24); var remainder = providedHrs % 24; var hrs = Math.floor(remainder); var min = Math.floor(60*(remainder-hrs));

 

Hope this will help you to solve your query... 😀 

Translate
arunpatidar
New Participant
Feb 19, 2020 10:45 AM UTC

Adding to above answer just make sure you have proper checks for day, hrs and min

https://stackoverflow.com/questions/49844323/javascript-convert-hours-and-minutes-into-days/49844499

 

Translate
Arun Patidar