Mirage
Mirage

Reputation: 31548

DATE_FORMAT() equivalent in PostgreSQL

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?

Upvotes: 0

Views: 5895

Answers (2)

John Woo
John Woo

Reputation: 263723

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'

Upvotes: 4

mvp
mvp

Reputation: 116187

SELECT *
FROM calendar
WHERE starttime::date = '2010-04-29'

Upvotes: 0

Related Questions