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)";
Szymon Lipiński
  • 27,098
  • 17
  • 75
  • 77
Les_Salantes
  • 317
  • 6
  • 20

1 Answers1

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'";
xdazz
  • 158,678
  • 38
  • 247
  • 274
  • 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. – Les_Salantes Aug 03 '12 at 09:55