What is does this do? (:db)

I have this piece of code: Time.now.beginning_of_day.to_s(:db) What exactly does the (:db) do?

It's an argument to the to_s method of the Time class that changes the date format. It's part of the Rails extensions to the core ruby classes. Here are a couple of other format options:

Time.now.to_s(:short) Time.now.to_s(:long)

My guess is that the :db format is used for storing dates in the database.

For more info take a look here: http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html

Aaron

Got it, thanks!

You might be interested in checking out Day 35 of the Rails Rubyisms Advent calendar [it only sounds ridiculous] which talks a little more about it. There’s a link there that used to go into quite a bit of depth about it but it seems not to be active right now. At any rate, you’ll probably learn a heck of a lot from that calendar anyhow. I know I did.

RSL

You might be interested in checking out Day 35 of the Rails Rubyisms Advent calendar [it only sounds ridiculous] which talks a little more about it. There's a link there that used to go into quite a bit of depth about it but it seems not to be active right now. At any rate, you'll probably learn a heck of a lot from that calendar anyhow. I know I did.

Wow, thanks for the tip. Real nice :slight_smile: