Forum: Ruby on Rails How to change Date format

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D69cd9081a425b5c8b5efa6b0633135c?d=identicon&s=25 Rahul Ha (aveo)
on 2007-04-23 11:44
Hi all,
I am using InstantRails with MySQL-Front. Date is stored in format
yyyy-mm-dd
in database. I want to retrieve and show date in dd-mm-yyyy in my
view.rhtml.
How can I change it to dd-mm-yyyy form.
Please help me out.

Thanks
C91098dc76d7ad473165ef24fe805312?d=identicon&s=25 Nanyang Zhan (xain)
on 2007-04-23 14:13
Rahul Ha wrote:

> How can I change it to dd-mm-yyyy form.
> Please help me out.

there may be a method to do this job,
at least you can code a helper yourself, like
def my_date(date)
 "#{date.day}-#{date.month}-#{date.year}"
end
Be45ffb84c0c25c351960879576ce315?d=identicon&s=25 o_O (Guest)
on 2007-04-23 14:16
(Received via mailing list)
<a href="http://corelib.rubyonrails.org/classes/
Time.html#M000264">strftime method</a>

my_time.strftime("%d-%m-%Y")

On Apr 23, 11:44 am, Rahul Ha <rails-mailing-l...@andreas-s.net>
34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2007-04-23 14:18
(Received via mailing list)
Nanyang Zhan wrote:
>  "#{date.day}-#{date.month}-#{date.year}"
> end
>
>
If you just need to reformat the date object when you print it, look at
the strftime function in the API.

http://corelib.rubyonrails.org/classes/Time.html#M000264

Cheers
Mohit.
This topic is locked and can not be replied to.