# Ordinalizing a date

**URL:** <https://www.ruby-forum.com/t/ordinalizing-a-date/61425>\
**Category:** Rails\
**Created:** [May 23, 2006, 11:47pm UTC](https://www.ruby-forum.com/t/ordinalizing-a-date/61425 "2006-05-23T23:47:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [May 23, 2006, 11:47pm UTC](https://www.ruby-forum.com/t/ordinalizing-a-date/61425/1 "2006-05-23T23:47:33Z")

</div>

I’m trying to use the ordinalize() method to ordinalize a day. Here’s  
how far I’ve gotten:

@reportday = Time.now.at\_beginning\_of\_week.strftime("%d").to\_i  
@ordinalized\_reportday = “#{@reportday}”.ordinalize

I was thinking it wasn’t working because the date is being returned as a  
string, however I added the .to\_i and still it returns an error.

The error I’m getting is:

undefined method `ordinalize’ for “22”:String

Any ideas?

Thanks.

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [May 24, 2006, 2:06am UTC](https://www.ruby-forum.com/t/ordinalizing-a-date/61425/2 "2006-05-24T02:06:29Z")

</div>

2006/5/24, Ben [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’m trying to use the ordinalize() method to ordinalize a day. Here’s  
> how far I’ve gotten:
> 
> @reportday = Time.now.at\_beginning\_of\_week.strftime(“%d”).to\_i  
> @ordinalized\_reportday = “#{@reportday}”.ordinalize
> 
> I was thinking it wasn’t working because the date is being returned as a  
> string, however I added the .to\_i and still it returns an error.

Yes, to\_i gives you Fixnum, as script/console shows:

> > @reportday = Time.now.at\_beginning\_of\_week.strftime(“%d”).to\_i  
> > =\> 22  
> > @reportday.class  
> > =\> Fixnum

However, you spoil everything with the next lineâ??“#{@reportday}” gives  
you a string:

> > “#{@reportday}”.class  
> > =\> String

You can either do this way: @ordinalized\_reportday =  
@reportday}.ordinalize,  
or all at once:

@ordinalized\_reportday =  
Time.now.at\_beginning\_of\_week.strftime(“%d”).to\_i.ordinalize

HTH

Regards,  
Rimantas

---

<div class="post-metadata">

**Author:** ![ben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/df788c/32.png) [@ben](https://www.ruby-forum.com/u/ben)\
**Post date:** [May 24, 2006, 3:08am UTC](https://www.ruby-forum.com/t/ordinalizing-a-date/61425/3 "2006-05-24T03:08:21Z")

</div>

On 5/23/06, Rimantas L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 2006/5/24, Ben [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > I’m trying to use the ordinalize() method to ordinalize a day. Here’s  
> > how far I’ve gotten:

[http://rails.techno-weenie.net/tip/2006/4/2/show\_ordinalized\_days\_when\_formatting\_times](http://rails.techno-weenie.net/tip/2006/4/2/show_ordinalized_days_when_formatting_times)
