DateTime - Quarter Hour Rounding Rule for Payroll

SteveSteve Member Posts: 81
Hello All,

I'm completing a payroll system within Navision and the data received is in DateTime fields and requires rounding (using the 15/7 quarter hour rule). I have figured a solution for this whereas I bring to the minutes to int and evaluate them against a table and then decide if the round is up or down and then try to evaluate this back to time and the back to date time.

This method is very clunky with several areas that could potentially fail especially on a 11:59pm (23:59) punch that would require change both date and time to the next day.

The rules are as follows.

If the minute are

00-07 round to 00
08-15 round to 15
16-22 round to 15
23-30 round to 30
31-37 round to 30
38-45 round to 45
46-52 round to 45
53-59 round to 60 ---> or the next day if 11:59PM (23:59)

Does anyone have ideas to streamline this process?

Thanks
Steve

Answers

  • matttraxmatttrax Member Posts: 2,309
    Well you can use DateTime2Time (or maybe DT2Time, haven't used in a long time) to extract the time part of your value. There's also DateTime2Date for your case where the user works into the next day.

    From there you can determine the number of seconds / minutes / hours using the FORMAT function. Then a large CASE statement should do.

    May be an easier way, but it's early on a Saturday morning and I'm still a little tired. :lol:
  • Bjarne_AstrupBjarne_Astrup Member Posts: 11
    Hi Steve,

    That is very easy

    ROUNDDATETIME(DateTime,15 * 60000)

    Best Regards

    Bjarne
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Hi Steve,

    That is very easy

    ROUNDDATETIME(DateTime,15 * 60000)

    Best Regards

    Bjarne

    I have never seen that function. Must take a look and see what it does.
    David Singleton
  • SteveSteve Member Posts: 81
    Works great thanks
    Steve
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Hi Steve,

    That is very easy

    ROUNDDATETIME(DateTime,15 * 60000)

    Best Regards

    Bjarne


    Neat function, I never saw it before, thanks for pointing it out.
    David Singleton
Sign In or Register to comment.