Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gunjack -> question for you

Status
Not open for further replies.

Bramvg

IS-IT--Management
Jan 16, 2001
135
BE
Hi Gunjack,

I posted a message on this forum (see beneth) but I have not received a sollution. It's quiet important to me and you helped me before many times, so I am more or less counting on your expertise! ;-)

I'm trying to find a find to compare two 'times'. I tried to use datecompare, but as the function indicates it's only to compare two dates.

I would like to know the difference betweed an start and an end time, including a day. Because someone can access my website at midnight and continue 'the day after'.
E.g.: starting at monday on 23.59 and stop on tuesday 01.00u

E.g:

Starttime: 11:15:20 [HH:MM:SS]
Endtime: 12:16:21 [HH:MM:SS]

Should I also include the day?

The result should be:
01:01:01 [HH:MM:SS]

Is theire a way of doing this?

Many thanks in advance.
Bram
 
OK you're right I'm GUNJACK but I know the answer.

Try using

<CFSet Start= #CreateDateTime(2000,1,1,10,30,00)#>
<CFSET End = #CreateDateTime(2000,1,1,11,35,00)#>
<CFOUTPUT>#DateDiff(&quot;N&quot;,Start,End)#</CFOUTPUT>

Make sure you use a DateTime variable otherwise it will get confused when the Date changes.

Have fun, Maybe Gunjack can spread some further light on the subject (Sorry I didn't answer your previous post)
 
Hi tlhawkins

Thank you very much! This has helped me a lot already!
It does exactly what I needed! Just one more question, what do you think is the best way of calculating this into minutes and seconds?

I give an example: in your example the result is 65 minutes. Which is 'not quiet correct'. This should be displayed as: 1 hour and 5 minutes, and let's say 15 seconds.

Could I ask you how this is done best?

With many thanks
bram
bram
 
Sorry Bramvg,

I should have given you all of that info.

DateDiff(&quot;N&quot;,Start,End) Gives minutes.

DateDiff(&quot;S&quot;,Start,End) Gives Seconds so,


DateDiff(&quot;S&quot;,Start,End) / 60 = minutes from seconds and the remainder (Use Mod) is the seconds left over.
There are otherways but that is probably the most efficient.

I don't have time right now to test the MOD part so I'll let you figure that out :)
 
Hey Bramvg,

Sorry I couldn't reply sooner but I've been swamped in my consulting business so I haven't been on the forums much lately. I'm glad Tlhawkins could answer your question. I'll expand on his answer a little in case you still need help.

Here's what I would recommend:

<cfset sDate=&quot;03/01/2001 11:30:15 am&quot;>
<cfset eDate=&quot;04/01/2001 01:30:15 pm&quot;>

<cfset sec=DateDiff(&quot;s&quot;,sDate,eDate)>
<cfset days=int(sec/86400)>
<cfset hours=int((sec-(days*86400))/3600)>
<cfset minutes=int((sec-(days*86400)-(hours*3600))/60)>
<cfset seconds=(sec-(days*86400)-(hours*3600)-(minutes*60))>

<cfoutput>Time difference is #days# days, #hours# hours, #minutes# minutes, and #seconds# seconds.
</cfoutput>

Hope this helps,
GJ
 
Hi GunJack,

Thank you very much! Meanwhile I had found something else too, based on the code of Tlhawkins, but it was much more complicated according to me.

Again, you have been of supergreat help!

With kind and best regards
bram
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top