Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Time ranges Post Reply Post New Topic
Author Message
Kathleen
Newbie
Newbie
Avatar

Joined: 31 Dec 2007
Location: United States
Online Status: Offline
Posts: 17
Quote Kathleen Replybullet Topic: Time ranges
    Posted: 31 Dec 2007 at 6:19am
Hello, new Crystal User again.  My next problem is that I need to report a number of "situations" per shift of work.  Meaning, from 7:00 am to 3:00 pm. I need to count "incidents" then count from 3:00 pm to 11:00pm - - and then from 11:00 pm to 7:00am. 
 
I created formulas that ask for the information between these times, but when I double check the information, I'm not getting the correct numbers.  Can someone help me out with a formula to more accurately obtain this information?  I am using greater than and less than but the 7:00 am to 3:00 pm still shows zero incidents.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 31 Dec 2007 at 4:17pm
I'm having trouble visualizing exactly where the problem would be, so it might help if you expand on the problem or possible show the record selection formula you are using.

What I'm wondering is whether you are including the data with the time range as well. Is is possible that the "less than" condition is miscalculating due to the fact that the field could also be taking the date into account and the change of days between times is throwing it off?
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Kathleen
Newbie
Newbie
Avatar

Joined: 31 Dec 2007
Location: United States
Online Status: Offline
Posts: 17
Quote Kathleen Replybullet Posted: 02 Jan 2008 at 6:08am
In the first running total below, I am trying to calculate the number of incidents that take place between 3:00 pm and 11:00 pm (second shift).  I was told to try this calculation and I'm getting numbers, but I'm not exactly sure how this calculation knows to count "incidents".
 
ctime (#03:00 pm#)<{@time} and ctime (#11:00 pm#)>{@time}
 
In the next running total below, I am trying to calculate the number of incidents that take place between 7:00 am and 3:00 pm (first shift).  I was told to try this calculation and I'm getting numbers for second and third shift, but nothing for first shift.  First shift is where the number should be the highest - and the numbers I'm getting for second and third shift aren't correct either.
 
({Incident.IncTime}>"07:00 AM" and {Incident.IncTime}<"03:00 PM")
 
What I really want to do is count the number of incident DTS that occur between the time periods of each shift so I can compare which shift has the most incidents and see if there is a trend. 
 
I so appreciate any assistance you can be with this.  Being new, some of these calculations are over my head.
 
Thanks.
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 02 Jan 2008 at 8:22am
As an extremely critical question, what kind of values are your @time and IncTime fields?  Are they Time values, or, more likely, DateTime values?

The simplest solution is to make sure you are using CTime on both sides of the comparison.  If you are using DateTime values, this will pull out only the time value.  However, that does mean that it will ignore the date value.  This may be an issue for the shift that straddles midnight.

As another tip, make sure you are including one (and only one) of your endpoints.  With your current formulas, you'll never capture any incidents that occur at exactly 3:00 pm.

Also, I'd recommend using the range data type, or using the BETWEEN operator, rather than using "less than" and "greater than" operators.

So, for your running total, try:
CTime(@time) IN CTime(#15:00#) TO_ CTime(#23:00#)

Look at the critical changes here.  By using CTime on @time, we make sure we are only looking at the time piece of the value.  "IN" and "TO" are part of the range operation.  By putting the underscore after "TO" we are telling it to ignore 23:00 (i.e., consider the first time to be part of this shift, but the last time to be part of next shift).  The military time is just personal preference on my part.  I consider it to be less error-prone than trying to use "am" and "pm."  But, then, I work with a bunch of military types.

To answer the other question you snuck in there, the running total doesn't know it's counting incidents.  It just knows that it's counting rows.  Every time a new row pops up in that time frame, it adds 1 to the current total.

In your second formula, I have a sneaking suspicion that Crystal might not be doing the implicit conversion in the way you expect.  If it is converting IncTime to a string, instead of "07:00 AM" to a time, you are asking which one comes first alphabetically.  Now, 9 times out of 10, it works out to be the same.  But, occasionally, it's just not.  Especially as you haven't explicitly told Crystal what format to use for the conversion.  While you're trying to get a handle on things, it is best to always use explicit conversions.  So, try something like:

CTime({Incident.IncTime}) BETWEEN CTime("07:00") AND CTime("15:00")

I went with the BETWEEN structure here just to demonstrate it.  However, notice something.  There is no way to tell it to ignore the endpoints.  If you use BETWEEN, then any incident which occurs at exactly 15:00 will get counted on two different shifts.



As a tip to help you as a newbie, try breaking the problem down into smaller pieces, and attacking it that way.  Create a formula that just returns CTime(Incident.IncTime), and display it on the report.  Display your running total on the report.  Try to narrow down which specific piece of the formula is returning an unexpected value.  This will greatly help you to correct whatever mistake you might have made.


IP IP Logged
Kathleen
Newbie
Newbie
Avatar

Joined: 31 Dec 2007
Location: United States
Online Status: Offline
Posts: 17
Quote Kathleen Replybullet Posted: 07 Jan 2008 at 3:02pm
Hello and thanks for your recent response.  I do have the CTime values counting, but I still have one issue.  I have changed everything to military time (easier, you're right), however, I cannot get the formulas to count over the midnight time.  Meaning, I have a shift that goes from 23:00 to 07:00, but for some reason, the formula CTime(@time) IN Ctime ("23:00") to_ Ctime(#07:00#) is not reading all the information.
 
I run test information and the items from 23:00 to 00:00 are not being counted in this calculation but all the others from 00:00 to 07:00 are being counted.
 
Have any more great advice for me?
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 08 Jan 2008 at 4:11am
Try breaking it up into two ranges.

CTime(@time) IN CTime("23:00") TO_ CTime("24:00")
OR
CTime(@time) IN CTime("00:00") TO_ CTime("07:00")


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.