Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How do I use DateDiff to determine the difference in seconds ?

Posted on 2003-03-23
Medium Priority
Last Modified: 2013-12-24

I've got this script which will display the Difference in the times like so:

Days, Hours, Minutes

But I want it to display the difference like:

Days, Hours, Minutes, Seconds

Here is the script I am currently using:

<CFSET days = DateDiff("d",Now(),date2)>
<CFSET hours = DateDiff("h",Now(),date2) - (24 * days)>
<CFSET minutes = DateDiff("n",Now(),date2) - (24 * 60 * days) - (60 * hours)>
<CFOUTPUT>#days# days, #hours# hours, #minutes# minutes</CFOUTPUT>

This would display something like:
3 days, 2 hours, 34 minutes

I need it to also display the seconds, I just can't seem to work out the maths that's all :)

If any one knows the answer please let me know.

Thanks in advance.
Question by:markh51
  • 2
  • 2

Expert Comment

ID: 8191148
<cfset date2='#now()#'>
<CFSET days = DateDiff("d",Now(),date2)>
<CFSET hours = DateDiff("h",Now(),date2) - (24 * days)>
<CFSET minutes = DateDiff("n",Now(),date2) - (24 * 60 * days) - (60 * hours)>
<CFSET Seconds = DateDiff("s",Now(),date2) - (24 * 60 * days) - (60 * hours) - ( 60 * minutes) >
<CFOUTPUT>#days# days, #hours# hours, #minutes# minutes seconds #Seconds#</CFOUTPUT>


Accepted Solution

demarco earned 220 total points
ID: 8191230
ah no thats crap

function GetSpanDate(dateObj, days, hours, minutes, seconds){
  var timeDiff = CreateTimeSpan(days, hours, minutes, seconds);
  var spanDate = dateObj+timeDiff;
  return "{ts '" & DateFormat(spanDate, "yyyy-mm-dd ") & TimeFormat(spanDate, "HH:mm:ss") & "'}";


Author Comment

ID: 8191233
Sorry, that doesn't work.

It is displaying the seconds as the TOTAL amount. i.e if there was 6 days and 12 hours diffrence it was displaying the seconds something like "552271 seconds"

Author Comment

ID: 8191358
Thanks mate

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question