Forum: Ruby on Rails sql server, date and time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E2489efc6ec10ec818b71965909ea109?d=identicon&s=25 Jin Lee (Guest)
on 2006-05-03 22:44
(Received via mailing list)
Hey there all,

Is there some way to tell rails or sql server to ignore the time in a
datetime field when doing a comparison?

For example, if I do something like

select * from users where registration_date = ?, @date

where @date might equal some user input like '03/14/2006'

The result is nothing returned, because in my tables the datetime
field looks like this:

3/14/2006 4:04:00 PM

I would like to tell rails or sql server to ignore the time, so that
these rows will be returned as well. Anyone with any ideas? I'm sure
this is something trivial and I'm just not seeing it.

Thanks alot!
Jin
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-05-03 23:34
(Received via mailing list)
Hello Jin,

> Is there some way to tell rails or sql server to ignore the time in a
> datetime field when doing a comparison?
>
> For example, if I do something like
>
> select * from users where registration_date = ?, @date
>
> where @date might equal some user input like '03/14/2006'

Check your SQL Server manual, there must be a way
to convert a datetime to a date. In MySQL, sth like :

  select * from users where date(created_at)="2006-05-03"

is possible.

   -- Jean-François.
E2489efc6ec10ec818b71965909ea109?d=identicon&s=25 Jin Lee (Guest)
on 2006-05-04 06:43
(Received via mailing list)
Hey thanks for the tip Jean. For those that care/want to know, I found
out the problem, its the way SQL Server handles datetime variables.
Unlike oracle and many other databases, there isnt a to_date or date()
function that extracts just the date only. The two ways around this
are to convert it to string (with time removed) or to do a BETWEEN
mm/dd/yy 00:00:00 (midnight) and mm/dd/yy 12:59:59 which covers the
entire day.

Jin
This topic is locked and can not be replied to.