Vote count:
0
There is a table with DATETIME field named 'created_at'. I try execute two queries like this:
SELECT * FROM myTable WHERE created_at BETWEEN '2015-03-15 10:25:00' AND '2015-03-25 10:30:00';SELECT * FROM myTable WHERE created_at BETWEEN STR_TO_DATE('2015-03-15 10:25:00', '%Y-%m-%d %H:%i:%s') AND STR_TO_DATE('2015-03-25 10:30:00', '%Y-%m-%d %H:%i:%s');
I always used the first query, but recently came across an article in which describes that the second approach is the best way to compare DATETIME. Unfortunately, it does not contain any explain why that approach is the best way.
Now, I have some questions:
- Is there any difference between these two approaches?
- Which way is more preferable?
Thanks!
asked 3 mins ago
STR_TO_DATE() vs CONSTANT when comparing DATETIME field
Aucun commentaire:
Enregistrer un commentaire