2016-03-07 113 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; 

请注意,月和年参数未被引用。