Print Page | Close Window

Time difference between two DateTime fields

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=9071
Printed Date: 03 May 2024 at 1:25am


Topic: Time difference between two DateTime fields
Posted By: Mellison
Subject: Time difference between two DateTime fields
Date 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?



Replies:
Posted By: DBlank
Date 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.


Posted By: Mellison
Date 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




Print Page | Close Window