Following is my query where I am fetching order wise payments on latest first basis.
I wish to fetch OrderPayment
created_at
here.
If I write <%= OrderPayment.last.created_at%>
I get 2019-06-28 16:31:12 +053
which is a date, and I'm currently using <%= order_payment["created_at"]%>
where I get 2019-06-28T11:01:12.686086
which is a string.
Why am I getting such a weird representation?
@order_payments = OrderPayment.select("order_id, json_agg(order_payments.* order by order_payments.created_at desc) as details").includes(order:).order("order_id desc").group(:order_id)
#iterating @orderpayments for listing
<% @order_payments.each do |order_detail| %>
<%details = order_detail.details%>
<%=order_payment["created_at"]%>
<%end%>
if i do <%= Time.at(DateTime.parse(order_payment["created_at"])).strftime("%d-%m-%y %I:%M %p")%>
i get output like OrderPayment.last.created_at but i want to know whats the correct way to do it?
I think in your situation database and your rail environment time zones are different. and its returning db value as it is with timezone you should try Time.zone.parse(//your query//)
It will return time and date with current time zone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.