Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TIME ROUNDING FORMULA??

Status
Not open for further replies.

DOGWATCH

Programmer
Mar 11, 2004
120
US
Sorry, I am a newbie at crystal.

I have this formula

Formula#1

Code:
Formula=Cdbl(Sum ({@cRegular},usp_rptTimeSheet;1.Vehicle_Name})/60)

and I need to apply a formula to round the value off to the nearest 1/4 hour.

here is the formula I believe I need to apply to that equation:

Formula#2

Code:
datetimevar x := CurrentDateTime;
DATEADD("n", (DATEPART("n", x) + 14) / 15 * 15 - DATEPART("n",x), x);

CurrentDateTime is the time value Returned by the First expression.

Can anyone explain how to apply formula 2 to formula 1 ?? Thanks in advance!!!!!!!!
 
Since you didn't share what your summing (it's some formula, minutes???), it's difficult to give an exact answer, consider posting technical information when requesting it.

If you're returning HOURS.DECIMALHOURS Try:

round(x*4)/4

-k
 
let me elaborate
Code:
Formula=Cdbl(Sum ({@cRegular}, {usp_rptTimeSheet;1.Vehicle_Name})/60)
This formula will give a sum of a list of time values
like 8:00+4:00+8:22 would equal 20:22min.

However part of the requirements of this report is that I round up the Time sum expression to the nearest 15 minute interval. For example 22:22 should be converted to 22:30 and 10:05 should be converted to 10:15

This sort of forumula would probably handle the needed calucation of rounding.

datetimevar x := CurrentDateTime;
DATEADD("n", (DATEPART("n", x) + 14) / 15 * 15 - DATEPART("n",x), x);

however in my case, x should be equal to Cdbl(Sum ({@cRegular}, {usp_rptTimeSheet;1.Vehicle_Name})/60)

I am just not sure how to plug that expression into my formula. Any one have any idea what my formula would be written like using the DATEADD calulation on my time expression??

Sorry I am a SQL dev and really new to crystal =(.





 
Just more background, I am using Crystal Reports 8 and it is connecting to SQL 7 Database.
 
Your formula might be overly complicated, check my post.

As for your time summing, it may not work as you think if I understand correctly that @cRegular contains HH.DECMIALHH data.

Just sum the field directly (don't divide by 60) and use my formula.

-k
 
My mistake, this formula
Code:
Formula=Cdbl(Sum ({@cRegular}, {usp_rptTimeSheet;1.Vehicle_Name})/60)

Will actually give you the sum of time in minutes which is divided by 60 to get hours.

However I tried this formula
Code:
[Formula=Cdbl(Sum ({@cRegular}, {usp_rptTimeSheet;1.Vehicle_Name})*4)/4

that still doesn't round off the minutes right even if I divide that by 60.

Any ideas?





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top