irb
#Get current time
[1] pry(main)> dt=DateTime.now
=> Wed, 23 Dec 2020 05:34:58 +0000
#Process only date information with parse
[2] pry(main)> today=Date.parse(dt.strftime("%Y/%m/%d %H:%M:%S"))
=> Wed, 23 Dec 2020
#Define a date
[3] pry(main)> dt2 = DateTime.new(2020,12,23,5,6,7)
=> Wed, 23 Dec 2020 05:06:07 +0000
#Process only date information with parse
[4] pry(main)> the_day=Date.parse(dt2.strftime("%Y/%m/%d %H:%M:%S"))
=> Wed, 23 Dec 2020
#today == the_day
[5] pry(main)> the_day == today
=> true
** Status settings ** I want to display today's number of orders on the top screen of the administrator of the EC site. Order model: Order
orders_controller
def top
dt=DateTime.now #First, get today's date. Like this(=> Wed, 23 Dec 2020 05:34:58 +0000)
today=Date.parse(dt.strftime("%Y/%m/%d %H:%M:%S")) #Extract only the date
orders=Order.all #For the time being, I will pull all the order information.
@sum=0 #For the total number. * Note that it is not initialized separately.
#@sum = @sum +When set to 1, "@What is sum? I get the error.
orders.each do |x| #Since it is a science system, it is defined as x.
dt2=x.created_at
the_day=Date.parse(dt2.strftime("%Y/%m/%d %H:%M:%S"))
if today == the_day
@sum = @sum + 1
end
end
end
Recommended Posts