# ActiveRecord simple question about date

**URL:** <https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567>\
**Category:** Rails\
**Created:** [November 19, 2013, 3:59pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567 "2013-11-19T15:59:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [November 19, 2013, 3:59pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567/1 "2013-11-19T15:59:32Z")

</div>

Hi all, i have User model with bdate: string  
Try :

> User.find(2).bdate  
> =\> Wed, 09 May 1945  
> User.find(2).bdate.to\_s  
> =\> “1945-05-09”

But if i run:

> User.where(bdate: “1945-05-09”)  
> =\> []

Why???

---

<div class="post-metadata">

**Author:** ![rusik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rusik](https://www.ruby-forum.com/u/rusik)\
**Post date:** [November 19, 2013, 4:10pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567/2 "2013-11-19T16:10:40Z")

</div>

On 19 November 2013 14:07, rusik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all, i have User model with bdate: string  
> Try :
> 
> > User.find(2).bdate  
> > =\> Wed, 09 May 1945  
> > User.find(2).bdate.to\_s  
> > =\> “1945-05-09”

Are you sure bdate is of type string in the database? If so then why  
does it appear to interpret it as a date in your first example?

Colin

---

<div class="post-metadata">

**Author:** ![rusik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rusik](https://www.ruby-forum.com/u/rusik)\
**Post date:** [November 19, 2013, 7:37pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567/3 "2013-11-19T19:37:33Z")

</div>

yes, it is string. I find decision , i am using date without zero’s like  
this:  
User.where(bdate: “1945-5-9”)  
, 19 2013 ., 19:09:01 UTC+4 Colin L. :

---

<div class="post-metadata">

**Author:** ![rusik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rusik](https://www.ruby-forum.com/u/rusik)\
**Post date:** [November 19, 2013, 9:52pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567/4 "2013-11-19T21:52:00Z")

</div>

On 19 November 2013 18:36, rusik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> yes, it is string. I find decision , i am using date without zero’s like  
> this:

Just to convince us show us the users table entry from db/schema.rb.

Colin

---

<div class="post-metadata">

**Author:** ![rusik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rusik](https://www.ruby-forum.com/u/rusik)\
**Post date:** [November 19, 2013, 11:22pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567/5 "2013-11-19T23:22:40Z")

</div>

Colin L. wrote in post #1127964:

> On 19 November 2013 18:36, rusik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > yes, it is string. I find decision , i am using date without zero’s like  
> > this:
> 
> Just to convince us show us the users table entry from db/schema.rb.

Just a thought, but if the birthday is truly being stored in a string  
(varchar) field, doesn’t that make localizing your application somewhat  
more difficult?

05/09/1945 - U.S.A  
09.05.1945 - Europe  
1945年5月9日 - Japan  
Wednesday, May 9, 1945 - U.S.A Long Format

---

<div class="post-metadata">

**Author:** ![rusik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rusik](https://www.ruby-forum.com/u/rusik)\
**Post date:** [November 19, 2013, 8:27pm UTC](https://www.ruby-forum.com/t/activerecord-simple-question-about-date/237567/6 "2013-11-19T20:27:49Z")

</div>

On Tue, Nov 19, 2013 at 10:36 AM, rusik [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> yes, it is string.

Uh, well.

If the datatype of that column were String, would you think you’d  
be likely to get different results from bdate and bdate.to\_s?

> > > > User.find(2).bdate  
> > > > =\> Wed, 09 May 1945  
> > > > User.find(2).bdate.to\_s  
> > > > =\> “1945-05-09”

–  
Hassan S. ------------------------ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[Hassan Schroeder | about.me](http://about.me/hassanschroeder)  
twitter: @hassan
