Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Time difference between two DateTime fields Post Reply Post New Topic
Author Message
Mellison
Newbie
Newbie
Avatar

Joined: 20 Nov 2009
Location: India
Online Status: Offline
Posts: 15
Quote Mellison Replybullet 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?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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.
IP IP Logged
Mellison
Newbie
Newbie
Avatar

Joined: 20 Nov 2009
Location: India
Online Status: Offline
Posts: 15
Quote Mellison Replybullet 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

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
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



This page was generated in 0.023 seconds.