Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Formula for hours Post Reply Post New Topic
Author Message
gaby
Newbie
Newbie


Joined: 23 Aug 2012
Location: United Kingdom
Online Status: Offline
Posts: 11
Quote gaby Replybullet Topic: Formula for hours
     Posted: 31 Oct 2012 at 5:59am
Hi All,

I hope I explain this well enough!

I am trying to look at how many hours a day and what hours of the day a group of people are doing certain activities.

I have data which states the activities, the date and time started and the date and time finished. I also have a formula which tells me how long they take doing that activity in minutes.

What I would like is a formula or something which tells me what hours of the day that job covers. The time periods can be anything from a few minutes to 24 hours and we are trying to access when are peak times for certain activities.

Not sure this is even possible!

any help very much appreciated

Thanks
Gaby
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 01 Nov 2012 at 6:37am
This IS possible, but it will be a bit tedious to set up.
 
Assuming you're grouping by activity and that for each hour you want a count of how many of that activity are occuring.
 
For each hour in the day, you're going to create a formula that looks something like this (which I'll call {@Hour1} because it looks at the time between 1 am and 2 am):
NumberVar startHour := Hour({myTable.StartDateTime});
NumberVar endHour := Hour({myTable.EndDateTime});

if startHour < endHour then //all time is in the same day
  if startHour <= 1 and endHour >= 1 then 1 else
else //the time spans over more than one day
  if startHour <= 1 or endHour >= 1 then 1 else 0
 
The Hour function returns the hour as a number between 0 and 23.  So, for example, 1 pm would return 13 not 1.
 
I haven't tested this so I'm not absolutely certain it will work, but it should give you a start.
 
To get the counts for each hour, sum that hour's version of this formula.  This sum should work at any grouping level.
 
-Dell
 
IP IP Logged
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