Coldfusion DateDiff - How to show as Hours and Minutes

I'm using DateDiff to display a 'countdown' to an expiry date - pulling the expiry date/time from a field in the database, and comparing it against the current time.

I then use CFSET to display the number of hours and a separate one for minutes, however the minutes are the total minutes (i.e 2 Hours displays as 2 Hours / 120 Minutes).

The Hour and Minutes display are shown seperately (for styling purposes), so I need them to be displayed as separate elements.  

So, effectively what I want to display is (assuming the expiry time is 2 hours, 15 minutes away);

2 Hours
15 Minutes

This is what I have so far to work with;

<cfset e_hours = #datediff("h",now(),expires)#>
<cfset e_mins = #datediff("n",now(),expires)#>

I'm fairly sure I can simply do some mathematical additions to the minutes to remove the hours from the figure, but everything I've tried so far has not been accurate.  Any pointers much appreciated!
MaxafiAsked:
Who is Participating?
 
SidFishesConnect With a Mentor Commented:
this should work for you

<cfset expires="01/30/2008 3:32 PM">

<cfset e_hours = #datediff("h",now(),expires)#>
<cfset e_mins = #datediff("N",now(),expires)#>

<cfoutput>
To Expiry = #e_hours# Hours #((e_mins/60)-e_hours)*60# Minutes
</cfoutput>
0
 
MaxafiAuthor Commented:
Works perfectly, thanks! :-)
0
 
rob_lorentzCommented:
try something like this......

<cfset t_now = now()>

<cfset expires = DateAdd("n", 39, t_now)>  <!--- bogus expire time --->

<cfset e_hours = datediff("h", t_now, expires )>
<cfset e_mins = datediff("n", t_now, dateAdd("h", (e_hours * -1), expires))>

<cfoutput>
 expires #expires#<br>
 e_hours #e_hours#<br>
 e_mins #e_mins#<br>
</cfoutput>


of course
0
All Courses

From novice to tech pro — start learning today.