Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: converting hours and minutes to hours Post Reply Post New Topic
Author Message
eckler78
Newbie
Newbie
Avatar

Joined: 07 Nov 2017
Online Status: Offline
Posts: 10
Quote eckler78 Replybullet Topic: converting hours and minutes to hours
    Posted: 07 Feb 2018 at 7:50am
Hello,
I need to get the difference between two date and time fields. I have done so with the below formula, but it spits out the value in HH:MM. I need the output to be HH.HH, in hours only. So not 1:12 (one hour, 12 minutes), but 1.2 (1.2 hours).

CStr (Round (DateDiff ("n", {TA_LABOR.TIME_IN}, {TA_LABOR.TIME_OUT}) \ 60), "#") + ':' +
CStr (Round (DateDiff ("n", {TA_LABOR.TIME_IN}, {TA_LABOR.TIME_OUT}) MOD 60), "00")

Thank you for any help!

Edited by eckler78 - 08 Feb 2018 at 3:07am
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 07 Feb 2018 at 12:46pm
The Round (DateDiff ("n", {TA_LABOR.TIME_IN}, {TA_LABOR.TIME_OUT}) \ 60)  should get you the hours (if I am reading it correctly). So is this what you needed?
IP IP Logged
eckler78
Newbie
Newbie
Avatar

Joined: 07 Nov 2017
Online Status: Offline
Posts: 10
Quote eckler78 Replybullet Posted: 08 Feb 2018 at 3:07am
Thank you kevlray. I have tried the formula you posted, but this returns just 1.00 hours. I need 1.2 hours. It appears to round down to the nearest hour. The formula I posted returns 1:12, one hour 12 minutes, I need this converted to 1.2 hours.
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 08 Feb 2018 at 4:17am
Then remove the Round function at the beginning and see what you get.
IP IP Logged
eckler78
Newbie
Newbie
Avatar

Joined: 07 Nov 2017
Online Status: Offline
Posts: 10
Quote eckler78 Replybullet Posted: 08 Feb 2018 at 4:23am
(DateDiff ("n", {TA_LABOR.TIME_IN}, {TA_LABOR.TIME_OUT}) \ 60) still returns 1.00
IP IP Logged
eckler78
Newbie
Newbie
Avatar

Joined: 07 Nov 2017
Online Status: Offline
Posts: 10
Quote eckler78 Replybullet Posted: 08 Feb 2018 at 4:32am
time in field = 1/22/2018 7:52:42AM
time out field = 1/22/2018 9:04:03AM
IP IP Logged
eckler78
Newbie
Newbie
Avatar

Joined: 07 Nov 2017
Online Status: Offline
Posts: 10
Quote eckler78 Replybullet Posted: 09 Feb 2018 at 5:18am
OK, i got the below formula to work, but can anyone simplify it so it can be understood?

cstr(int((DateDiff ("n", {TA_LABOR.TIME_IN}, {TA_LABOR.TIME_OUT})) / 60),0) & "." & right(cstr((tonumber(right("0" & cstr((DateDiff ("n", {TA_LABOR.TIME_IN}, {TA_LABOR.TIME_OUT})) mod 60,0),2))/60)),2)
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.000 seconds.