prateek prateek - 1 month ago 8
Ruby Question

Retrieve without timestamp

I am trying to fetch updated_at without timestamp in order by but unable to do so. I am using date_trunc function but unable to get proper result.Apart from this is there any other function which can give me only date not timestamp

users = User.members(current_user,params).order("date_trunc('datepart', updated_at) DESC, upvotes DESC").paginate(:per_page => PER_PAGE,:page => (params[:page] || 1))

Answer

Try following.

users = User.members(current_user,params).order("updated_at.to_date DESC, upvotes DESC").paginate(:per_page => PER_PAGE,:page => (params[:page] || 1))

or

users = User.members(current_user,params).order('updated_at.strftime("%Y-%m-%d") DESC, upvotes DESC').paginate(:per_page => PER_PAGE,:page => (params[:page] || 1))

or

users = User.members(current_user,params).order('updated_at.strftime("%F") DESC, upvotes DESC').paginate(:per_page => PER_PAGE,:page => (params[:page] || 1))