Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REPLACE FUNCTION next_cm(now TIMESTAMP WITH TIME zone, months INTEGER) RETURNS TIMESTAMP WITH TIME zone AS $$
- << outerblock >>
- DECLARE
- m_offset INTEGER;
- BEGIN
- m_offset := months;
- IF (get_cm(now) + ('17:00'::INTERVAL)) < now THEN
- m_offset := m_offset + 1;
- END IF;
- RETURN get_cm(date_trunc('month',now) + (m_offset||'month')::INTERVAL) + ('16:30'::INTERVAL);
- END;
- $$ LANGUAGE plpgsql;
- CREATE OR REPLACE FUNCTION get_cm(now TIMESTAMP WITH TIME zone) RETURNS TIMESTAMP WITH TIME zone AS $$
- << outerblock >>
- DECLARE
- BEGIN
- RETURN date_trunc('month', now) + ((((8 + 4 - date_part('isodow',date_trunc('month', now)))::integer%7) + 14)||'days')::INTERVAL;
- END;
- $$ LANGUAGE plpgsql;
- -- Ergebnis:
- # SELECT next_cm(now(),0), next_cm(now),1);
- next_cm | next_cm
- ------------------------+------------------------
- 2011-07-15 16:30:00+02 | 2011-08-19 16:30:00+02
- (1 ROW)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement