S
S
Sergey Beloventsev2018-05-15 21:00:04
Yii
Sergey Beloventsev, 2018-05-15 21:00:04

How to organize search by date?

There is a
datatime= 2018.05.18 format field,
how can I find the date range from 05/01/2018 to 05/20/2018 with an Activerecord query?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Savitsky, 2018-05-15
@PRC

$query = TvojaModel::find()
->where(['>=', $column_1, '2018-05-01'])
->andWhere(['<=', $column_2, '2018-05-20'])
->all();

A
Antarit, 2018-05-16
@Antarit

$query = Model::find()
->where(['between', 'datatime_column', '2018-05-01', '2018-05-20']);

Read the details in the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question