0

I have this query in mysql

SELECT * 
FROM `calendar` 
WHERE DATE_FORMAT(startTime, "%Y-%m-%d") = '2010-04-29'

How can i convert to Postgresql query?

John Woo
  • 258,903
  • 69
  • 498
  • 492
Mirage
  • 30,868
  • 62
  • 166
  • 261

2 Answers2

4

Basically, the query in MYSQL which uses DATE_FORMAT() converts date into string. If you want to compare it with date, don't use DATE_FORMAT() but instead DATE(). Try this, in PostgreSQL, casting timestamp into date,

SELECT * 
FROM   "calendar"
WHERE  "startTime"::date = '2010-04-29'
Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Somehow my query is not returning the correct results. In my database coulmn currently my date is stored as this `2012-10-05 09:00:00+08 ` when i try "startTime"::date = '2012-10-05' i am not getting any result – Mirage Nov 02 '12 at 06:56
  • what is the data type of `startTime` column? – John Woo Nov 02 '12 at 06:57
  • datetime , i think i have problem somewhere in my joins , i will check that. thanks for help – Mirage Nov 02 '12 at 07:01
0
SELECT *
FROM calendar
WHERE starttime::date = '2010-04-29'
mvp
  • 111,019
  • 13
  • 122
  • 148