I want to convert seconds to days, hours and minutes Currently, it works just for hours and minutes but not for days. Can you please support me tell me what I did wrong:
<cfscript>
seconds = '87400';
midnight = CreateTime(0,0,0);
time = DateAdd("s", seconds, variables.midnight);
date= xxxxxxxxxxxxxxxxxxxxx???
</cfscript>
<cfoutput>
#DateFormat(variables.date, 'd')# not working
#TimeFormat(variables.time, 'HH:mm')#
</cfoutput>
For the value 87400 the expected result is
- 1 Days, 0 hours, 16 minutes
If I take 94152 seconds it will be:
- 1 days, 3 hours, 22 minutes
The only issue i have is to get the correct days ... hours and minutes are diplayed but not the correct days
thank you for all the support
I understand from your question that you don't need to get a certain date and time along a timeline, but convert a total amount of seconds in days, hours and minutes. To do that you don't necessary need to use cfml time and date functions like CreateTime() or DateAdd(). You just may need these in order to get a reference point of time or date along a timeline, which doesn't seem to be the case, otherwise you would know the value of your starting
datevariable. Thus, you can solve this with plain rule of three. There may be simpler methods, so I'm posting an alternative only.We know that:
Thus, your calcualtion within cfml could be like so:
That outputs: