gpt4 book ai didi

ruby-on-rails - rails : Find tasks that were created on a certain day?

转载 作者:数据小太阳 更新时间:2023-10-29 07:10:36 26 4
gpt4 key购买 nike

我有一个任务列表(名称、starts_at),我试图在每日 View 中显示它们(就像 iCal)。

def todays_tasks(day)
Task.find(:all, :conditions => ["starts_at between ? and ?", day.beginning, day.ending]
end

我不知道如何将 Time.now(例如“2009-04-12 10:00:00”)动态转换为一天的开始(和结束),以便进行比较。

最佳答案

def todays_tasks(now = Time.now)
Task.find(:all, :conditions => ["starts_at > ? AND < ?", now.at_beginning_of_day, now.at_end_of_day])
end

瞧!

关于ruby-on-rails - rails : Find tasks that were created on a certain day?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/742277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com