sql - Get first (and last) day of month - expression simplification -
i need date, 30 (later use 90 or 18o) days before first day of current (and previous) month. wrote this, think it's unnecessarily complicated, come here help. it's way how can simplify this:
ib_encodedate(extract(year (dateadd(-30-datediff(day cast(extract(month current_date) || '-1-' || extract(year current_date) date) date 'now') day current_date))), extract(month (dateadd(-30-datediff(day cast(extract(month current_date) || '-1-' || extract(year current_date) date) date 'now') day current_date))),extract(day (dateadd(-30-datediff(day cast(extract(month current_date) || '-1-' || extract(year current_date) date) date 'now') day current_date))))
in database have dates in double
, have use function ib_encodedate
convert date double
, compare date in database. function have prototype:
ib_encodedate(int year, int month, int day)
the same need write last day of month.
thanks help.
seems need this:
select dateadd (-extract(day current_date)+1 day current_date) first_day_of_month, dateadd (-30 day dateadd (-extract(day current_date)+1 day current_date)) a_month_ago, dateadd (-90 day dateadd (-extract(day current_date)+1 day current_date)) three_months_ago, dateadd (-180 day dateadd (-extract(day current_date)+1 day current_date)) six_months_ago rdb$database
using function dateadd firebird can accomplish this.
Comments
Post a Comment