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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding Time 1

Status
Not open for further replies.

TerriO

Technical User
Jan 9, 2002
84
US
I have a datediff value that comes up to be 3.17 (3 hours and .17 of an hour) how do I convert and round it to the nearest .25 of an hour?

Terri
 
Try this: where x is your field


round(x*4)/4


Mike
 
3.17 (3 hours and .17 of an hour)

I suppose you could try this

//@QuarterHourRound

WhilePrintingRecords;
NumberVar Hour;
NumberVar Whole;
NumberVar Fraction;
StringVar result;

Whole := DateDiff(whatever the expression is);
Hour := Truncate(whole,0);
Fraction := Whole - hour;

if Fraction < .125 then
result := totext(Hour,0) + &quot;:00&quot;
else if Fraction < .375 then
result := totext(Hour,0) + &quot;:15&quot;
else if Fraction < .625 then
result := totext(Hour,0) + &quot;:30&quot;
else if Fraction < .875 then
result := totext(Hour,0) + &quot;:45&quot;
else if Hour + 1 > 23 then
result := &quot;00:00&quot;
else
result := totext(Hour + 1,0) + &quot;:00&quot;;

result;

that should do it.





Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top