Date conversion

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?
Thanks.

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?
Thanks.

I found the answer. ‘%B %d, %Y’.

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 _on or _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 D. [email protected]

Your column should be named _on or _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 D. [email protected]

I have a post on defining named time formats. This way you’re not
littering your app with direct calls to #strftime.

http://rails.techno-weenie.net/tip/2005/11/20/defining_custom_date_time_formats


rick
http://techno-weenie.net