How to get date format in result set?
Posted
by Prasanna
on Stack Overflow
See other posts from Stack Overflow
or by Prasanna
Published on 2010-04-20T05:22:36Z
Indexed on
2010/04/20
5:53 UTC
Read the original article
Hit count: 305
ruby-on-rails
|mysql
I have a sql to get data form mysql their I used dateformat to convert date required format Here is the sql
SELECT
m.id,
m.subject,
m.body,
m.read,
m.hide,
m.thread_id,
DATE_FORMAT(m.sent_date, '%d-%b-%Y') sent_date,
u.username to_name
FROM
messages m,
users u
WHERE
u.school_id = m.school_id AND
u.id = m.to_user_id AND
m.school_id = 18 AND
m.user_id = 53 AND
m.status = 'sent'
ORDER BY m.sent_date DESC
When I run this sql directly in mysql it works fine, sent_date comes as (19-Apr-2010). When I excute this in ruby, in result set the sent_date is stores as (Tue Apr 20 00:00:00 UTC 2010)
messages = Message.find_by_sql(sql)
puts messages[0]['sent_date']
puts statement prints "Tue Apr 20 00:00:00 UTC 2010"
how to get same date format in mysql result and ruby result set.
Thanks
© Stack Overflow or respective owner