I'm using RoR and mysql database. I want to convert timestamp column to string, so i have the SQL:
@books = Book.find_by_sql("select id, name, date_format(borrow_date, '%m/%d/%Y') borrow_date from books")
@books[0].borrow_date => 'Sun, 03 Aug 2014 17:00:00 PDT -07:00'
When i output the borrow_date like @books[0].borrow_date, i got un-formatted string 'Sun, 03 Aug 2014 17:00:00 PDT -07:00' which is not expected. I want "08/03/2014"
If i change alias name that different than the column name, i get expected data string.
@books = Book.find_by_sql("select id, name, date_format(borrow_date, '%m/%d/%Y') borrow_date_other from books")
@books[0].borrow_date_other => "08/03/2014"
I don't want to format date string in ruby code since i need to pull the same data from oracle database and just want to convert to string before use.
Why RoR doesn't allow same column name and alias name? Do i miss something? Thank you in advance.