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.
Rahul H. (Guest)
on 2007-04-23 13: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
Nanyang Z. (Guest)
on 2007-04-23 16: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
o_O (Guest)
on 2007-04-23 16: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 <removed_email_address@domain.invalid>
Mohit S. (Guest)
on 2007-04-23 16:18
(Received via mailing list)
Nanyang Z. 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.