I have recently been informed that the use of the BETWEEN
method in SQL is somewhat unreliable, and I should therefore be using DATEDIFF()
. However, another programmer has informed me this is not the case and the BETWEEN
method works brilliantly in all cases as long as the date is formatted correctly.
Please could someone settle this debate by stating which method is better and why?
At the moment my date range SQL looks like this:
DATEDIFF(d,'01-Jan-1970',SIH.[Something_Date]) >= 0 AND DATEDIFF(d,'01-Jan-2013',SIH.[Something_Date]) <= 0
However, I would much rather write it like this if I can be sure it is reliable:
SIH.[Something_Date] BETWEEN '01-Jan-1970' AND '01-Jan-2013'
In this particular case I am using MsSQL, however, I have tagged MySQL as I would like to know if this applies here as well
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…