本文介绍了如何迭代天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个循环天的代码.我希望出席者的列登录和注销将自动从开始日期开始填充,并在结束日期结束.

I have a code for looping days.this to make leaves. I want column signin and signout on attendance will filling automatically start at startdate and end at enddate.

exp I input :
startdate: 2012-11-08 01:30:00
enddate: 2012-11-10 01:30:00
i want output like this: 

2012-11-08 01:30:00
2012-11-09 01:30:00
2012-11-010 01:30:00

 for i in 0..((@leafe.enddate - @leafe.startdate).to_i)
                 @attendance = Attendance.new

                 @attendance.signin = '2012-11-08 01:30:00' #value must chang automatically
                 @attendance.signout = '2012-11-08 10:30:00'#value must chang automatically
                 @attendance.user_id = @leafe.user_id
                 @attendance.save
            end

先感谢

推荐答案

如果startdate为Date类型,为什么不这样做,

If startdate is of type Date, why not just do,

@attendance.signin = @leafe.startdate+i
@attendance.signout = @leafe.startdate+i

这篇关于如何迭代天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 13:38