How do I select the last date in a table where the column name is Lars.
I have tried this:
<%= Reklamer.where(":dato => :dato, AND :name => :name", :date => Date.last, :name => "Lars") %>
I have tried this:
<%= Reklamer.where(name: 'Lars').order('dato ASC').limit(1).select('dato').inspect %>
Output:[#<Reklamer dato: "2011-02开发者_运维百科-15 23:53:28">]
I need just a datetime format like: 2011-02-15 23:53:28
How do I do that?
You have to order by the date and select a single record:
<%= Reklamer.where(name: 'Lars').order('dato DESC').first %>
You can accomplish this by limiting to a single record as well:
Reklamer.where(name: 'Lars').order('dato DESC').limit(1)
If you just want the last date from the last entry, you can do this:
Reklamer.where(name: 'Lars').last.dato
精彩评论