我有一個名爲'cost'的浮動表和名爲'created_at'的時間戳。基於日期的輸出數組(按天的銷售數字)
我希望它輸出一個數組,並將上個月每個特定日的費用相加。
喜歡的東西:
@newarray = [] #creating the new array
month = Date.today.month # Current Month
year = Date.today.year # Current Year
counter = 1 # First Day of month
31.times do #for each day of the month (max 31)
#adding sales figures for that day
@newarray.push(Order.sum(:cost, :conditions => {:created_at => "#{year}-#{month}-#{counter}"}))
counter = counter + 1 #go onto next day
end
然而,由於所有的時間戳有一個時間以及這行不通。
爲窮人頭銜道歉,我似乎無法想到一個明智的。
這看起來不錯,仍然試圖瞭解代碼。目前它也輸出日期 - 我如何刪除它?如何在每個條目之間添加逗號分隔符? – vectran 2010-03-07 23:57:28