Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: calculate hours difference Post Reply Post New Topic
Author Message
sanchezgmc06
Senior Member
Senior Member
Avatar

Joined: 21 Jan 2011
Online Status: Offline
Posts: 107
Quote sanchezgmc06 Replybullet Topic: calculate hours difference
    Posted: 16 Jun 2020 at 9:41am
hi

I need to be able to calculate the difference in hours form 2 separate date and time fields

fields
Date 1
Time 1

Date 2
Time 2


I attempted using the following formula however I dont believe the date and time are stored in the date field.


local numbervar tt := datediff('h',date1,date2);
local numbervar d := truncate(tt/24,0);
local numbervar h := remainder(tt,24);
local stringvar tt_d := totext(d,0,"") + ' days ';
local stringvar tt_h := totext(h,0,"") + ' hours';
local stringvar tt_string := tt_d & tt_h

thank you!!

IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 18 Jun 2020 at 4:58am
If there is no time component tied to the fields in question.  Then thee is no way to properly do a hour difference.

Have you done test formulas to see what intermediate values you get?
Also there no reason to calculate the days form the hours.  You could do a date diff of days an put that in variable.
IP IP Logged
sanchezgmc06
Senior Member
Senior Member
Avatar

Joined: 21 Jan 2011
Online Status: Offline
Posts: 107
Quote sanchezgmc06 Replybullet Posted: 18 Jun 2020 at 5:49am
This ended up working for me

Thank you for your help

DateDiff("h", DateTime({StartDate},{StartTime}), DateTime({EndDate},{EndTime}))
& " Hours and " &
DateDiff("n", DateTime({StartDate},{StartTime}), DateTime({EndDate},{EndTime})) Mod 60
& " Minutes"
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.016 seconds.