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. -- Posted via http://www.ruby-forum.com/.
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''. -- Posted via http://www.ruby-forum.com/.
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 Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060105/89749e4d/PGP-0001.bin
> 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>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