# Format dates prior to index

**URL:** <https://www.ruby-forum.com/t/format-dates-prior-to-index/78697>\
**Category:** Ferret\
**Created:** [December 7, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/format-dates-prior-to-index/78697 "2006-12-07T22:28:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkahn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jkahn](https://www.ruby-forum.com/u/jkahn)\
**Post date:** [December 7, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/format-dates-prior-to-index/78697/1 "2006-12-07T22:28:19Z")

</div>

Hi all-

I would like to enable search in my application via Ferret and a number  
of my searchable classes contain dates (of type Time). When these  
classes are indexed, the dates are written per the standard to\_s output  
(e.g. “Wed Dec 07 08:56:04 CDT 2006”), which is not suitable for date  
range queries. Is it possible to format the dates before they are  
indexed (e.g. “20061207”) without writing additional methods that output  
the dates in this format?

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![jkahn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jkahn](https://www.ruby-forum.com/u/jkahn)\
**Post date:** [December 7, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/format-dates-prior-to-index/78697/2 "2006-12-07T22:53:14Z")

</div>

On 07.12.2006, at 22:28, Joshua Kahn wrote:

> output  
> the dates in this format?

Is there something wrong with writing an additional method that does  
the conversion? If you don’t need the extra precision of Time use  
Date. Its to\_s method will give you “2006-12-07” right away.

–  
Andy

---

<div class="post-metadata">

**Author:** ![jkahn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jkahn](https://www.ruby-forum.com/u/jkahn)\
**Post date:** [December 7, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/format-dates-prior-to-index/78697/3 "2006-12-07T22:54:59Z")

</div>

Nothing wrong, I was just hoping to avoid that. I will look into using  
Date.

Thanks.
