postgresql7.1
select to_char(next_day(to_date(:start_date, 'YYYY-MM-DD'),
'sunday')-(cast ('7 days' as interval)), 'YYYY-MM-DD') as start_date,
to_char(next_day(to_date(:start_date, 'YYYY-MM-DD'),
'sunday')-(cast ('1 day' as interval)), 'YYYY-MM-DD') as end_date
select to_char(to_date(to_date(:start_date,'YYYY-MM') + '1 month'::interval - '1 day'::interval , 'YYYY-MM-DD'), 'YYYY-MM-DD') as end_date
select j.mail_job_id, j.mail_class_id, j.subject, j.mails_sent, j.state,
j.track_links_p, p.first_names || ' ' || p.last_name as user_name,
to_char(j.execution_date, 'YYYY-MM-DD HH24:MI') as execution_date
from ml_mail_jobs j, acs_objects o, persons p
where j.state <> 'suspended'
and j.scheduled_date >= to_timestamp(:start_date, 'YYYY-MM-DD')
and j.scheduled_date < (to_timestamp(:end_date, 'YYYY-MM-DD') + '1 day'::interval)
and acs_permission__permission_p(j.mail_job_id, :user_id, 'read') = 't'
and o.object_id = j.mail_job_id
and p.person_id = o.creation_user
order by j.execution_date desc, lower(j.subject)