Comparing dates in rails

Yes, you can use comparison operators to compare dates e.g.: irb(main):018:0> yesterday = Date.new(2009,6,13) => #<Date: 4909991/2,0,2299161> irb(main):019:0> Date.today > yesterday => true But are you trying to compare a date to a datetime? If that’s the case, you’ll want to convert the datetime to a date then do the comparison. I hope this helps.

Best way to find the months between two dates

Start by defining some test cases, then you will see that the function is very simple and needs no loops from datetime import datetime def diff_month(d1, d2): return (d1.year – d2.year) * 12 + d1.month – d2.month assert diff_month(datetime(2010,10,1), datetime(2010,9,1)) == 1 assert diff_month(datetime(2010,10,1), datetime(2009,10,1)) == 12 assert diff_month(datetime(2010,10,1), datetime(2009,11,1)) == 11 assert diff_month(datetime(2010,10,1), datetime(2009,8,1)) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)