Today I Learned

hashrocket A Hashrocket project

Ecto Query "ago" and "from_now"

Ecto.Query has 2 very useful functions for Datetime querying. Here's ago/2:

from p in Post, where: p.published_at > ago(3, "month")

And here's from_now/2

from a in Account, where: a.expires_at < from_now(3, "month")

And finally this is the list of intervals that it's supported:

  • year
  • month
  • week
  • day
  • hour
  • minute
  • second
  • millisecond
  • microsecond
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.