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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 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