# Checkin date issue

**URL:** <https://www.ruby-forum.com/t/checkin-date-issue/147503>\
**Category:** Rails\
**Created:** [September 2, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/checkin-date-issue/147503 "2008-09-02T15:58:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 2, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/checkin-date-issue/147503/1 "2008-09-02T15:58:24Z")

</div>

in my DB, I have records with a DateTIme ‘starting\_at’ date

in my model, I wrote a named\_scope :

```
named_scope :planned_on_date, lambda {|aDate|
  {:conditions => ['state = ? AND starting_at = ?', 'planned',

```

aDate]}  
}

the problem is the time… , I only need to get all planned records on  
a defined date  
aDate = aDate.to\_date =\> Wed, 10 Dec 2008 nned to get all records at  
this date whatever time…

if I do  
Checkin.planned\_on\_date(aDate) then =\> []

is there a simple way to do that ? or should I use a range ?  
something like

```
named_scope :planned_on_date, lambda {|aBeginningDate,

```

anEndingDate|  
{:conditions =\> ['state = ? AND starting\_at BETWEEN ? AND ',  
‘planned’, aBeginningDate.change(:hour =\> 0, :minutes =\> 0, :seconds  
=\> 0, aBeginningDate.change(:hour =\> 23, :minutes =\> 59, :seconds =\>  
59) )]}  
}

all enlightment welcome

erwin

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 2, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/checkin-date-issue/147503/2 "2008-09-02T16:20:45Z")

</div>

On 2 Sep 2008, at 14:57, Erwin wrote:

> the problem is the time… , I only need to get all planned records on  
> a defined date  
> aDate = aDate.to\_date =\> Wed, 10 Dec 2008 nned to get all records at  
> this date whatever time…
> 
> if I do  
> Checkin.planned\_on\_date(aDate) then =\> []
> 
> is there a simple way to do that ? or should I use a range ?  
> something like

Either have the column be just a date or search a range.

Fred

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 2, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/checkin-date-issue/147503/3 "2008-09-02T17:21:14Z")

</div>

did not realize that I could use the MySQL DATE() function …

```
named_scope :planned_on_date, lambda {|aDate|
  {:conditions => ['state = ? AND DATE(starting_at) = ?',

```

‘planned’, aDate] }  
}

god

thanks

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [September 2, 2008, 5:33pm UTC](https://www.ruby-forum.com/t/checkin-date-issue/147503/4 "2008-09-02T17:33:36Z")

</div>

On 2 Sep 2008, at 16:20, Erwin wrote:

> did not realize that I could use the MySQL DATE() function …
> 
> named\_scope :planned\_on\_date, lambda {|aDate|  
> {:conditions =\> [‘state = ? AND DATE(starting\_at) = ?’,  
> ‘planned’, aDate] }  
> }

You can do that. it will be slower that searching on a range.

Fred
