# What is does this do? (:db)

**URL:** <https://www.ruby-forum.com/t/what-is-does-this-do-db/88850>\
**Category:** Rails\
**Created:** [March 15, 2007, 12:27am UTC](https://www.ruby-forum.com/t/what-is-does-this-do-db/88850 "2007-03-15T00:27:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 15, 2007, 12:27am UTC](https://www.ruby-forum.com/t/what-is-does-this-do-db/88850/1 "2007-03-15T00:27:40Z")

</div>

I have this piece of code:  
Time.now.beginning\_of\_day.to\_s(:db)  
What exactly does the (:db) do?

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 15, 2007, 5:39am UTC](https://www.ruby-forum.com/t/what-is-does-this-do-db/88850/2 "2007-03-15T05:39:10Z")

</div>

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](http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html)

Aaron

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 15, 2007, 7:35am UTC](https://www.ruby-forum.com/t/what-is-does-this-do-db/88850/3 "2007-03-15T07:35:18Z")

</div>

Got it, thanks!

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 17, 2007, 12:09pm UTC](https://www.ruby-forum.com/t/what-is-does-this-do-db/88850/4 "2007-03-17T12:09:54Z")

</div>

On Mar 15, 11:54 am, “Russell N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You might be interested in checking out Day 35 of the Rails R.isms 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 🙂

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [March 15, 2007, 3:56pm UTC](https://www.ruby-forum.com/t/what-is-does-this-do-db/88850/5 "2007-03-15T15:56:34Z")

</div>

You might be interested in checking out Day 35 of the Rails R.isms  
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
