Date conversion


#1

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.


#2

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’.


#3

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. removed_email_address@domain.invalid


#4

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. removed_email_address@domain.invalid

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