# How to fetch data using 'between in sql'?

**URL:** <https://discourse.cakephp.org/t/how-to-fetch-data-using-between-in-sql/274>\
**Category:** Uncategorized\
**Created:** [May 9, 2016, 8:11am UTC](https://discourse.cakephp.org/t/how-to-fetch-data-using-between-in-sql/274 "2016-05-09T08:11:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityaPansari](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@adityaPansari](https://discourse.cakephp.org/u/adityaPansari)\
**Post date:** [May 9, 2016, 8:11am UTC](https://discourse.cakephp.org/t/how-to-fetch-data-using-between-in-sql/274/1 "2016-05-09T08:11:23Z")

</div>

here is my code -  
`$appointments = $events->find('all')->where(['facility_id' => $this->request->data(['facilities'])]);`

And I have two variable holding dates - $from\_date and $to\_date. In the table , there are a column name ‘date’.

---

<div class="post-metadata">

**Author:** ![Xoubaman](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xoubaman/32/102_2.png) [@Xoubaman](https://discourse.cakephp.org/u/Xoubaman)\
**Post date:** [May 9, 2016, 10:43am UTC](https://discourse.cakephp.org/t/how-to-fetch-data-using-between-in-sql/274/2 "2016-05-09T10:43:43Z")

</div>

Hint: is good to read the doc before posting.

Go to [http://book.cakephp.org/3.0/en/orm/query-builder.html](http://book.cakephp.org/3.0/en/orm/query-builder.html) and search for `between()`.

---

<div class="post-metadata">

**Author:** ![adityaPansari](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@adityaPansari](https://discourse.cakephp.org/u/adityaPansari)\
**Post date:** [May 9, 2016, 10:52am UTC](https://discourse.cakephp.org/t/how-to-fetch-data-using-between-in-sql/274/3 "2016-05-09T10:52:56Z")

</div>

Please tell me ,  
dateDiff(), how it works?
