[Rails] date conversion

Hasan Diwan
Thu, 05 Jan 2006 13:54:21 -0000

Juan:
On Jan 3, 2006, at 5:46 PM, Justin Hernandez wrote:

> I have the date saved in a database in the following format
> ''20060102170020''. How do I go about converting the date
in the
> format of
> January, 01, 1901? I searched all over and found something similiar
> using ''to_formatted_s''. However I only found support for
converting
> month to a three letter format (e.g. ''Jan''). Is there an
eaiser way?

Your column should be named <foo>_on or <foo>_at and be of the SQL
Date type. You can then use the strftime method to format the date as
you wish. As in:
model.bought_on.strftime("%B, %d, %Y") which will display the date in
the format you''ve requested.
Cheers,
Hasan Diwan <hasan.diwan@gmail.com>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part