Answer the question
In order to leave comments, you need to log in
How to replace strftime in Rails after switching to Postgres?
Switched from SQLite to PG and to constructions like: @today = Date.today.strftime("%d.%m.%Y")
or
def self.query_by_year_month(y, m)
where("strftime('%Y', date) = ? and strftime('%m', date) = ?", y, m)
end
PG::UndefinedFunction: ERROR: function strftime(unknown, date) does not exist
Answer the question
In order to leave comments, you need to log in
def self.by_month(month)
dt = DateTime.new(month) # на случай если строку передают
where("published_at >= ? and published_at <= ?", dt.beginning_of_month, dt.end_of_month)
end
Post.by_month(DateTime.new(1970, 1))
def self.query_by_year_month(y, m)
where("date_part('year', date) = ? and date_part('month', date) = ?", y, m)
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question