benonymus

benonymus

DateTime comparison in query

Hey there,

I have this code:

from(
      ge in query,
      join: e in assoc(ge, :event),
      where: e.start_date <= ^date
    )

As we know this can cause problems because of the date/datetime comparisons as it is described here for example : Date — Elixir v1.20.2

my questions is then how could I use DateTime.compare/2 with e.start_date here as the first argument?

Marked As Solved

NobbZ

NobbZ

As far as I remember, ecto does translate this into proper comparison on the SQL level, and the DateDtime struct isn’t actually involved in the comparison.

Last Post!

NobbZ

NobbZ

The linked article is 4 years old and probably refers to a version of elixir that is not only deprecated but literally dead.

At the time the article got released, ecto 1.0.7 was current. Today we are at 3.2.2.

The Ecto.DateTime module has been deprecated in 2.2.4.

So I won’t say that article is pointless, I’d just say its not applicable anymore today, but it might have had its worth back the day it has been published.

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement