无法过滤当前月份数据php

时间:2014-03-08 08:41:39

标签: php

我想过滤当前月份数据但遇到问题:

以“MAR”的形式获得英语的当前月份:

$months = array(01 => "JAN", 02 => "FEB", 03 => "MAR", 04 => "APR", 05 => "MAY", 06 => "JUN", 07 => "JUL", 08 => "AUG", 09 => "SEP", 10 => "OCT", 11 => "NOV", 12 => "DEC");
                                        $date = getdate();
                                        $month = $date['mon'];
                                        $Month_Name = $months[$month];
                                        echo $Month_Name;

php查询:

$query = oci_parse($con, "SELECT FIR.*, ACCUSED.* FROM FIR INNER JOIN ACCUSED ON FIR.FIR_NO = ACCUSED.FIR_NO WHERE FIR_DATE = '$Month_Name' ORDER BY FIR_DATE DESC");

现在的问题是,如果我FIR_DATE = '04-$Month_Name-14'这样做有效,我的日期格式就像08-MAR-14,但这不允许我获得月份数据。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我不确定我是否理解,但我认为这就是你想要的。

$query = oci_parse($con, "SELECT FIR.*, ACCUSED.* FROM FIR INNER JOIN ACCUSED 
ON FIR.FIR_NO = ACCUSED.FIR_NO WHERE 
TO_CHAR(TO_DATE(FIR_DATE, 'DD-MON-YYYY'), 'MON')= '$Month_Name' 
ORDER BY FIR_DATE DESC");

答案 1 :(得分:0)

要获得当前月份,您不需要这个。

echo date('M');

将以您要查找的格式显示它。 有更多格式可供选择,您可以在date() documentation page找到它们。