2016-03-07 117 views
-2

我想通過一個腳本,是在MySQL到PostgreSQL,但在mysql中產生的問題我一句這樣的:參考月份和年份PostgreSQL中

$q1="select * from noticias where month(fecha)='".$elmes."' and year(fecha)='".$elanio."'"; 

我得到以下錯誤:

Warning: pg_query(): Query failed: ERROR: no existe la funcion month(date) LINE 1: select * from noticias where month(fecha)='03' and year(fech...^HINT: Ninguna funcion coincide en el nombre y tipos de argumentos. Puede ser necesario agregar conversion explicita de tipos. in C:\xampp\htdocs\calendario\index.php on line 131

你如何看待PostgreSQL的月份和年份?

+0

你能用英文分享表格結構和錯誤信息嗎?謝謝 –

+1

你應該可以使用date_part:http://www.postgresql.org/docs/9.1/static/functions-datetime.html – purpleninja

+0

$ q1 =「select * from noticias where date_part(month)(fecha)=' 「。$ elmes。」'和date_part(year)(fecha)='「。$ elanio。」'「; ??????????? – Camaliet

回答

1
$q1="select * from noticias where date_part('month', fecha)=".$elmes." and date_part('year', fecha)=".$elanio; 

請注意,月和年參數未被引用。