0

I have a PostgreSQL table with a column name date_stamp and its data type is "date".
I need to execute the below query and it's not working. Can anyone help? Thank You.
(I am using PHP)

$DS = date('d m Y' ,$data['time_stamp']);       

$query = "SELECT id from ".$this->table_ud." WHERE user_id=43 AND date_stamp=to_date(".$DS.",YYYY MM DD)";
1
  • Got the answer. The problem was not with PostgreSQL. to_date() works just fine. Commented Aug 2, 2012 at 9:14

1 Answer 1

1

Not necessary to use to_date.

You could just do with:

$DS = date('Y-m-d' ,$data['time_stamp']);       
$query = "SELECT id from ".$this->table_ud." WHERE user_id=43 AND date_stamp='$DS'";
Sign up to request clarification or add additional context in comments.

1 Comment

are u sure that to_date() is not necessary? Initially I tried to do what you have suggested above and it didn't work. My guess was that php date() function returns a string and the date_stamp column in the table is of type date and that you cannot compare a string type with date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.