Hi, In my form I have date field set as ''datetime_select'' which is fine as I wanted it in the same format. But while displaying (list action) it displays date in long format i.e. ''Tue May 30 15:39:00 Central Daylight Time 2006''. How can I format it so that it will just be diaplyed as ''dd/mm/yyyy'' format? Thanks -- Posted via http://www.ruby-forum.com/.
Look at Time#strftime: http://corelib.rubyonrails.org/ <%= object.created_at.strftime("%d/%m/%Y") %> On 6/14/06, Ruby Rails <rajshrimilind@yahoo.com> wrote:> Hi, > In my form I have date field set as ''datetime_select'' which is fine as I > wanted it in the same format. But while displaying (list action) it > displays date in long format i.e. ''Tue May 30 15:39:00 Central Daylight > Time 2006''. How can I format it so that it will just be diaplyed as > ''dd/mm/yyyy'' format? > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Derek Haynes HighGroove Studios - http://www.highgroove.com San Mateo, CA | Atlanta, GA Keeping it Simple. 650.276.0908
Alterantively to using strftime every time you want to format a date, ie if you want this display application wide you can add ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( :default => ''%d/%m/%Y @ %H:%M: %p ) ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update( :default => ''%d/%m/%Y ) to the environment.rb Then you can just put something like <%= object.created_at.to_date %> and all the formatting is done for you. On 6/15/06, Derek Haynes <derek.haynes@highgroove.com> wrote:> > Look at Time#strftime: > > http://corelib.rubyonrails.org/ > > <%= object.created_at.strftime("%d/%m/%Y") %> > > On 6/14/06, Ruby Rails <rajshrimilind@yahoo.com> wrote: > > Hi, > > In my form I have date field set as ''datetime_select'' which is fine as I > > wanted it in the same format. But while displaying (list action) it > > displays date in long format i.e. ''Tue May 30 15:39:00 Central Daylight > > Time 2006''. How can I format it so that it will just be diaplyed as > > ''dd/mm/yyyy'' format? > > > > Thanks > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Derek Haynes > HighGroove Studios - http://www.highgroove.com > San Mateo, CA | Atlanta, GA > Keeping it Simple. > 650.276.0908 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060615/416d81f7/attachment-0001.html
Thanks guys I wasn''t aware of this! -- Posted via http://www.ruby-forum.com/.
On Thursday, June 15, 2006, at 2:53 PM, Daniel N wrote:>Alterantively to using strftime every time you want to format a date, ie if >you want this display application wide you can add > >ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( >:default => ''%d/%m/%Y @ %H:%M: %p ) > >ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update( >:default => ''%d/%m/%Y ) > >to the environment.rb > >Then you can just put something like ><%= object.created_at.to_date %> > >and all the formatting is done for you. > > > >On 6/15/06, Derek Haynes <derek.haynes@highgroove.com> wrote: >> >> Look at Time#strftime: >> >> http://corelib.rubyonrails.org/ >> >> <%= object.created_at.strftime("%d/%m/%Y") %> >> >> On 6/14/06, Ruby Rails <rajshrimilind@yahoo.com> wrote: >> > Hi, >> > In my form I have date field set as ''datetime_select'' which is >>fine as I >> > wanted it in the same format. But while displaying (list action) it >> > displays date in long format i.e. ''Tue May 30 15:39:00 Central Daylight >> > Time 2006''. How can I format it so that it will just be diaplyed as >> > ''dd/mm/yyyy'' format? >> > >> > Thanks >> > >> > -- >> > Posted via http://www.ruby-forum.com/. >> > _______________________________________________ >> > Rails mailing list >> > Rails@lists.rubyonrails.org >> > http://lists.rubyonrails.org/mailman/listinfo/rails >> > >> >> >> -- >> Derek Haynes >> HighGroove Studios - http://www.highgroove.com >> San Mateo, CA | Atlanta, GA >> Keeping it Simple. >> 650.276.0908 >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails >I just came across an interesting bug that crops up when you do this. On MySQL 5.0.21 if I use this trick, it prevents ''Date'' fields from updating properly. The same may happen with other types, but I haven''t tested them. It is probably safer to leave these settings alone and just force the formatting in the view. _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
On 13 Jul 2006 03:49:36 -0000, Kevin Olbrich < devlists-rubyonrails@devlists.com> wrote:> > > On Thursday, June 15, 2006, at 2:53 PM, Daniel N wrote: > >Alterantively to using strftime every time you want to format a date, ie > if > >you want this display application wide you can add > > > >ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update( > >:default => ''%d/%m/%Y @ %H:%M: %p ) > > > >ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.update( > >:default => ''%d/%m/%Y ) > > > >to the environment.rb > > > >Then you can just put something like > ><%= object.created_at.to_date %> > > > >and all the formatting is done for you. > > > > > > > >On 6/15/06, Derek Haynes <derek.haynes@highgroove.com> wrote: > >> > >> Look at Time#strftime: > >> > >> http://corelib.rubyonrails.org/ > >> > >> <%= object.created_at.strftime("%d/%m/%Y") %> > >> > >> On 6/14/06, Ruby Rails <rajshrimilind@yahoo.com> wrote: > >> > Hi, > >> > In my form I have date field set as ''datetime_select'' which is > >>fine as I > >> > wanted it in the same format. But while displaying (list action) it > >> > displays date in long format i.e. ''Tue May 30 15:39:00 Central > Daylight > >> > Time 2006''. How can I format it so that it will just be diaplyed as > >> > ''dd/mm/yyyy'' format? > >> > > >> > Thanks > >> > > >> > -- > >> > Posted via http://www.ruby-forum.com/. > >> > _______________________________________________ > >> > Rails mailing list > >> > Rails@lists.rubyonrails.org > >> > http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > >> > >> > >> -- > >> Derek Haynes > >> HighGroove Studios - http://www.highgroove.com > >> San Mateo, CA | Atlanta, GA > >> Keeping it Simple. > >> 650.276.0908 > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > I just came across an interesting bug that crops up when you do this. > On MySQL 5.0.21 if I use this trick, it prevents ''Date'' fields from > updating properly. The same may happen with other types, but I haven''t > tested them. > > It is probably safer to leave these settings alone and just force the > formatting in the view. > > _KevinKevin, Thanx for the heads up... --> Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060713/531fbb5b/attachment.html