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

x
Solved

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

Posted on 2003-03-23
Medium Priority
193 Views
Hi,

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.

0
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>

??
0

Accepted Solution

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

<cfscript>
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") & "'}";
}
</cfscript>

0

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"
0

Author Comment

ID: 8191358
Thanks mate
0

## Featured Post

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.