B
B
BonBon Slick2018-02-10 14:12:05
SQL
BonBon Slick, 2018-02-10 14:12:05

Which date selection is more correct?

There is a record, say User, with a field CreatedAt = 1999-11-12 15:32:55and many more users that were created that day.
There are two options for sampling:
1 - the first, sampling from this day 1999-11-12 00:00:00 to The 1999-11-13 00:00:00
request is something like this:

->select(*)
->from(User::class, 'alias')
->where('alias.createdAt >= :stratOfDay')
->setParameter(':startOfDay = 1999-11-12 00:00:00')
->where('alias.createdAt <= :endOfDay')
->setParameter(':endOfDay= 1999-11-13 00:00:00')

2 - or is this option more correct?
->from(User::class, 'alias')
->where('alias.createdAt >= :date')
->setParameter(':date= 1999-11-12')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-02-10
@BonBonSlick

The interval option is correct:
https://stackoverflow.com/questions/14104304/mysql...
The DATE() option is a time killer
And of course, using DATE() makes the index impossible, since you always need to go through it to calculate it over all values ​​and calculate)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question