Joined: 20 Nov 2009
Location: India
Online Status: Offline
Posts: 15
Topic: Time difference between two DateTime fields Posted: 09 Feb 2010 at 3:44am
Hi, I have two DateTime fields in the DB StartDateTime and EndDateTime.The format in which it is stored is follows "2/9/2010 4:02:40 PM".Now i want to find out the difference between the Date Time fields and display in HH:MM:SS format. i tried to use Date Diff formula as follows DateDiff("s",CDateTime(Date({ProcessInfo.EndTime})),CDateTime(Date({ProcessInfo.StartTime}))); but it is returning 0.0 when both the fileds are on the same day but only the time is different. how solve this problem?
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 09 Feb 2010 at 7:24am
you do a datediff using seconds then convert that value into time.
if it never goes over 24 hours you can display it by adding the total seconds to any midnight value. If it goes over 24 hours then you will have to decide how you want it displayed (e.g. 25 hours or 1 day and 1 hour)and write a formula accordingly. Search this site as there are multiple postings with sample code for this exact request.
Joined: 20 Nov 2009
Location: India
Online Status: Offline
Posts: 15
Posted: 10 Feb 2010 at 12:09am
Thanks for the reply, got the solution for it, it was giving 0.0 always because i am using only the date value and not the time value in the date diff fuction.This is how i fixed it DateDiff("s",CDateTime(Date({ProcessInfo.StartTime}),Time({ProcessInfo.StartTime})),CDateTime(Date({ProcessInfo.EndTime}),Time({ProcessInfo.EndTime}))); now i pass time value along with date, so that i get the exact seconds between two date Time fields
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum