Rails days between dates


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def days_between(date1, date2)
  2. yyyy1,mm1,dd1 = $3, $1, $2 if date1 =~ /(\d+)\/(\d+)\/(\d+)/
  3. date1_ts = Time.mktime(yyyy1,mm1,dd1).tv_sec
  4. yyyy2,mm2,dd2 = $3, $1, $2 if date2 =~ /(\d+)\/(\d+)\/(\d+)/
  5. date2_ts = Time.mktime(yyyy2,mm2,dd2).tv_sec
  6. (date2_ts - date1_ts)/60/60/24
  7. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.