ruby on rails - Every other date -
i have logic print out dates
def get_y_axis dates = "" ed = date.today sd = date.today - 30 sd.upto(ed) |date| dates << date.strftime("%b %d") dates << "|" end return dates end
it prints this
=> "jan 24|jan 25|jan 26|jan 27|jan 28|jan 29|jan 30|jan 31|feb 01|feb 02|feb 03|feb 04|feb 05|feb 06|feb 07|feb 08|feb 09|feb 10|feb 11|feb 12|feb 13|feb 14|feb 15|feb 16|feb 17|feb 18|feb 19|feb 20|feb 21|feb 22|feb 23|"
the problem need every other day...not every day ideas
mark's solution fine, wanted show each_with_index method
def get_y_axis dates = [] ed = date.today sd = date.today - 30 (sd..ed).each_with_index |date, i| dates << date.strftime("%b %d") if % 2 == 0 end dates.join("|") end
also, in solution, "|" appended after last date. guess dont want that.
Comments
Post a Comment