Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Days since January 1st, 2008 (See related posts)

// I'm in a challenge to do one pushup and one crunch for each day of the new year. This little Ruby snippet will tell me how many I have to do!

(DateTime.now - DateTime.new(2008,1,1)).to_i

Comments on this post

Caius posts on Mar 27, 2008 at 10:17
Don't forget to
require "date"
before running this snippet to make
DateTime
an available class.

require "date"
puts (DateTime.now - DateTime.new(2008,1,1)).to_i
mahlon posts on Mar 30, 2008 at 16:51
p Time.now.yday - 1

You need to create an account or log in to post comments to this site.


Click here to browse all 4829 code snippets

Related Posts