How to get the day of year in ruby?

Viewed 16128

What is the best way to get the day of the year for any specific date in Ruby?

For example: 31/dec/2009 should return day 365, and 01/feb/2008 should return day 32

5 Answers

You can use time without importing anything:

Time.new(1989,11,30).yday

or for now:

Time.now.yday
Related