U
U
Uzair Izha2016-02-04 22:40:51
PHP
Uzair Izha, 2016-02-04 22:40:51

How to compare a date in a selection from a database?

I have a date stored in the database in this form 2016-02-04 12:30:00 and
there is a variable that is compared with it in this form 2016-02-04 , that is, without time
For them to be equal

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2016-02-04
@UZEIR

datecolumn >= '2016-02-04' and datecolumn < '2016-02-04' + interval 1 day

If someone will offer at first glance a more compact solution date(datecolumn) = '2016-02-04' - immediately consider that such a condition in mysql, in principle, cannot use indexes.

Z
ZLOFENIX, 2016-02-04
@ZLOFENIX

You can try to do STR_TO_DATE('2011-12-21 02:20pm', '%Y-%m-%d %h:%i%p') and compare numbers already, which is more convenient, although it depends on the column type, if line - it will definitely be bad. If possible, it's better not to store the date in this form, IMHO.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question