Plpgsql function to compute "every other Friday"

Поиск
Список
Период
Сортировка
От C. Bensend
Тема Plpgsql function to compute "every other Friday"
Дата
Msg-id 05963a922dd2298b8a05d105bb143186.squirrel@webmail.stinkweasel.net
обсуждение исходный текст
Ответы Re: Plpgsql function to compute "every other Friday"  ("David Johnston" <polobo@yahoo.com>)
Re: Plpgsql function to compute "every other Friday"  (Andy Colson <andy@squeakycode.net>)
Re: Plpgsql function to compute "every other Friday"  (John R Pierce <pierce@hogranch.com>)
Re: Plpgsql function to compute "every other Friday"  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Hey folks,

   So, I'm working on a little application to help me with my
budget.  Yeah, there are apps out there to do it, but I'm having
a good time learning some more too.  :)

   I get paid every other Friday.  I thought, for scheduling
purposes in this app, that I would take a stab at writing a plpgsql
function to determine if a given date is a payday.  Here is what I
have so far:


CREATE OR REPLACE FUNCTION is_payday( d DATE ) RETURNS BOOLEAN AS $$

        DECLARE epoch DATE;
                days_since_epoch INTEGER;
                mult FLOAT8;
                ret BOOLEAN := FALSE;

BEGIN

        SELECT INTO epoch option_value
                FROM options WHERE option_name = 'payroll_epoch';

        SELECT INTO days_since_epoch ( SELECT CURRENT_DATE - d);

        *** here's where I'm stuck ***

        RETURN ret;

END;
$$ LANGUAGE plpgsql;


   OK.  So, I have a "starting" payday (payroll_epoch) in an options
table.  That is the first payday of the year.  I then calculate the
number of days between that value and the date I pass to the function.
Now I need to calculate whether this delta (how many days since
epoch) is an even multiple of 14 days (the two weeks).

   I have no idea how to do that in plpgsql.  Basically, I need to
figure out if the date I pass to the function is a payday, and if
it is, return TRUE.

   I would very much appreciate any help with this last bit of math
and syntax, as well as any advice on whether this is a reasonable
way to attack the problem.  And no - this isn't a homework
assignment.  :)

Thanks folks!

Benny


--
"Hairy ape nads."        -- Colleen, playing Neverwinter Nights





В списке pgsql-general по дате отправления:

Предыдущее
От: Howard Cole
Дата:
Сообщение: Re: Large Object permissions lost in transfer
Следующее
От: "David Johnston"
Дата:
Сообщение: Re: Plpgsql function to compute "every other Friday"