Boris Kuzevanov
Boris Kuzevanov

Reputation: 1302

Rails function or method like PHP date()

So i've date from database like '2014-03-10 12:43:00'. I'v tried to find some answer for me, but i have no results. In PHP i can do like this:

echo date('d/m/Y', strtotime(here my variable with date))

What can i use on rails ? I'v tried to do like this:

%= Date.strptime(call.datetime, '%d-%m-%Y %H:%i') %>

But i see error: no implicit conversion of ActiveSupport::TimeWithZone into String

Thanks!

Upvotes: 0

Views: 167

Answers (2)

DGM
DGM

Reputation: 26979

You are looking for strftime, not strptime.

<%= @date_variable.strftime('%d-%m-%Y %H:%M')

Note the %i you have doesn't seem to match up, check the docs to make sure you have the right format string.

Upvotes: 2

Boris Kuzevanov
Boris Kuzevanov

Reputation: 1302

This is my solution:

<%= call.datetime.strftime('%m/%d/%Y') %>

Upvotes: 1

Related Questions