I thought of the following:
You want to divide a day up into 12 or 6 equal
parts and round the datetime to the nearest increment.
DT: TDateTime;
date part + time part
DT = Trunc(DT) + frac(DT)
For your first requirement, the time part consists
of 1/12 * N with some remainder left over that you
want to round to the nearest N/12. Since round works
with N, not N/12, multiply by 12 for rounding
calculation:
frac(DT)*12 (for a fraction between 1/12 and 2/12 for
example, this will yield a number between 1 and 2).
Round this number:
round(frac(DT)*12) (this gives 1 or 2 for a DT
between 1/12 and 2/12)
Convert back to the original scale by dividing by 12
again:
round(frac(DT)*12) /12 This should be the required
nearest 2 hour increment value.
I haven't verified this, it is just my thoughts.
You could use a constant for the increment for better
programming of course. I have to do something similiar
so I hope this works :-).
Dave
--- Andries Bos <[EMAIL PROTECTED]> wrote:
> Hello
>
> I'm looking for a function to round an TDateTime to
>
> a) 2 and
> b) 4 hours;
>
> e.g. if its 15h10 it should round to 16h00 when
> using the 2-hours rouding.
> and at 4 hours interval it should be rounded to the
> nearest 24/4 hour.
>
> any ideas?
>
> regards
>
> andries
>
>
>
> __________________________________
> Yahoo! FareChase: Search multiple travel sites in
> one click.
> http://farechase.yahoo.com
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/i7folB/TM
--------------------------------------------------------------------~->
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/