My database(PostgreSQL) have some amount of data, so i need to retrieve the
data for current date only.But my doubt is how to compare the today date
with created_at field. Now am trying so many ways to find that.

Is this correct way * where created_at BETWEEN '2012-01-16 00:00:00.00000'
AND '2012-01-17 00:00:00.00000'...?*


Thank you
vishnu

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/VhCIfTW2ftcJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Robert Walker at Feb 3, 2012 at 6:13 pm

    amvis wrote in post #1043961:
    My database(PostgreSQL) have some amount of data, so i need to retrieve
    the
    data for current date only.But my doubt is how to compare the today date
    with created_at field. Now am trying so many ways to find that.

    Is this correct way * where created_at BETWEEN '2012-01-16
    00:00:00.00000'
    AND '2012-01-17 00:00:00.00000'...?*
    Answer by example:

    $ rails console
    1.9.3-p0 :001 > today = Date.today
    => Fri, 03 Feb 2012
    1.9.3-p0 :002 > tomorrow = Date.today + 1.day
    => Sat, 04 Feb 2012
    1.9.3-p0 :003 > orders = Order.where(:created_at => today...tomorrow)
    Order Load (0.7ms) SELECT "orders".* FROM "orders" WHERE
    ("orders"."created_at" >= '2012-02-03' AND "orders"."created_at" <
    '2012-02-04')

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Amvis at Feb 3, 2012 at 7:44 pm
    Thanks..



    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/AghPe-3qIR8J.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Philip Hallstrom at Feb 3, 2012 at 7:58 pm

    amvis wrote in post #1043961:
    My database(PostgreSQL) have some amount of data, so i need to retrieve
    the
    data for current date only.But my doubt is how to compare the today date
    with created_at field. Now am trying so many ways to find that.

    Is this correct way * where created_at BETWEEN '2012-01-16
    00:00:00.00000'
    AND '2012-01-17 00:00:00.00000'...?*
    Answer by example:

    $ rails console
    1.9.3-p0 :001 > today = Date.today
    => Fri, 03 Feb 2012
    1.9.3-p0 :002 > tomorrow = Date.today + 1.day
    => Sat, 04 Feb 2012
    1.9.3-p0 :003 > orders = Order.where(:created_at => today...tomorrow)
    Order Load (0.7ms) SELECT "orders".* FROM "orders" WHERE
    ("orders"."created_at" >= '2012-02-03' AND "orders"."created_at" <
    '2012-02-04')
    Be sure to check your timezones...

    Date.today does not honor the timezone set within Rails...

    You might want to use Time.zone.now.to_date instead...

    -philip

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Amvis at Feb 3, 2012 at 6:13 pm
    one query got it from guides.rubyonrails.org

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/9P-2Rz9ZWzoJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 3, '12 at 5:16p
activeFeb 3, '12 at 7:58p
posts5
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase