Reputation: 125902
I want to get an Ecto.DateTime
value that represents the current time.
How can I do that?
Upvotes: 0
Views: 895
Reputation: 1364
While DateTime.utc_now |> Ecto.DateTime.cast
works, there is a simpler way with Ecto.DateTime.utc
It's basically the same but with a different default precision:
iex(30)> DateTime.utc_now |> Ecto.DateTime.cast
{:ok, #Ecto.DateTime<2016-09-27 19:55:38.542000>}
iex(31)> Ecto.DateTime.utc
#Ecto.DateTime<2016-09-27 19:55:45>
iex(32)> Ecto.DateTime.utc(:usec)
#Ecto.DateTime<2016-09-27 19:55:48.162000>
Upvotes: 2
Reputation: 125902
DateTime.utc_now
and cast
it.{:ok, datetime} = DateTime.utc_now |> Ecto.DateTime.cast
Upvotes: 0