Definitive Guide To Dates In Ruby

Is this really a definitive guide? Oh hell no! I just thought it was a great title and it might make you click here more often. I also heard google like autoritative words like difinitive.

Well, what do I know about dates? Nothing much other than they suck, except in excel, they’re GREAT. If all computer programming languages could take a page out of Excel’s book on dates, I would be a LOT HAPPIER.

When I first got into computer programming, I’m pretty sure I attempted to subtract dates like 1/12/2016 - 1/1/2016 and I actually expected it to work. I mean that’s how I would have done it in excel. But it’s quite a bit different in Ruby and other programming languages and I always fucking forget how it works. That’s why I’m documenting it here, to get my mind in the right place.

As long as I can avoid the minutia, or the shitty parts of programming, I’m pretty good. One of the shitty parts is remembering, how the fuck do dates work.

Creating a Date Date.civil(year, m, d)

new\_date = Date.civil(2016, 2, 1)
=> February 1st 2016

Subtracting Two Dates (date2 - date1).to_i

Post Content