Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:35:47+00:00 2026-06-06T22:35:47+00:00

I would like to compare a date entered in a search field (e.g., 04.07.2012)

  • 0

I would like to compare a date entered in a search field (e.g., 04.07.2012) with a date from my table (a datetime column called date). However, I can’t seem to get my SQL query straight.

What I tried:

find(:all, :conditions => ['\'to_timestamp(date, \'DD Mon YYYY\')\' LIKE \'to_timestamp(?, \'DD Mon YYYY\')\'', '#{query}']) 

but it fails:

PG::Error: ERROR:  syntax error at or near "DD"
LINE 1: ...s".* FROM "projects"  WHERE ('to_timestamp(date, 'DD Mon YYY...
                                                             ^
: SELECT "pacients".* FROM "projects"  WHERE ('to_timestamp(date, 'DD Mon YYYY')' LIKE 'to_timestamp('#{query}', 'DD Mon YYYY')')

I’m a real novice as far as (postgre)SQL is concerned and I would really appreciate some hints in the right direction of writing this query.

Thanks a million!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:35:50+00:00Added an answer on June 6, 2026 at 10:35 pm

    As meager pointed out there are a couple of issues here:

    • incorrect string interpolation
    • making the database do more work than necessary and using LIKE when you can do date searching more directly:

    Let ActiveRecord format the date inputs use straight SQL to compare the dates, something like:

    start_date = Date.civil(2012, 7, 4)
    end_date = Date.civil(2012, 7, 20)
    User.where(["date BETWEEN ? AND ?", start_date, end_date])
    

    Converting the source date and the dates in the database to a timestamp formatted like a string and then using LIKE is very round-about and poor performing as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to compare two columns in the same table. I want to
I would like to be able to compare two classes derived from the same
I would like to compare a date to the current date. could you please
I am pulling a datetime from a mysql db and i would like to
I would like to compare the two dates ,one date is which the 02
I have a table power with a datetimetz field called sample_time and a column
I would like to compare 2 date, which stored in database as String. When
I would like to compare a date to the current date in Django, preferably
I need to compare a timestamp to a date. I would just like to
Ok, I have a due date formatted like this: 08/31/2012 (M/D/Y). What I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.