Skip to content

Instantly share code, notes, and snippets.

@braynm
Last active March 26, 2021 03:10
Show Gist options
  • Save braynm/d024ac7ba02e514cbf0654d08d56d1e2 to your computer and use it in GitHub Desktop.
Save braynm/d024ac7ba02e514cbf0654d08d56d1e2 to your computer and use it in GitHub Desktop.
Ecto query by date
...
import Ecto.Query
date = ~D[2021-03-22]
# fetch by date
query = from a in Schema, where: fragment("?::date", a.createdAt) == ^date
Repo.all(query) # fetch
# fetch by range
query = from a in Schema, where: fragment("?::date", a.createdAt) >= ^start_date and fragment("?::date", a."createdAt") <= ^end_date
Repo.all(query) # fetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment