Last active
March 26, 2021 03:10
-
-
Save braynm/d024ac7ba02e514cbf0654d08d56d1e2 to your computer and use it in GitHub Desktop.
Ecto query by date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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