【发布时间】:2015-02-26 12:05:34
【问题描述】:
我需要一些帮助来过滤日期数组。
下面的查询将打印一个包含所有条目的表格。但我不想过滤日期。 例如,如果今天是“2014 年 30 月 12 日”,我想显示 2014 年 12 月 30 日和“较新”的所有条目,而不是“2014 年 30 月 12 日”的第一个条目。
“appointment.start_time”是一个 varchar2,其输出如下:2014-11-28T15:35:00
在 $stid 中,我使用 substr 修剪“appointment.start_time”,因此输出类似于“2014-11-28”。
但是我该如何放入过滤器呢?
这样的?
foreach ($row as $item)
if ($item->dateitem >= $startDate &&
$item->dateitem <= $endDate)
$newarray[] = $item;
你能帮帮我吗?
亲切的问候, 里奇
----------------------------------- ---- 查询 php -------------------------------------------- --------------
$stid = oci_parse($conn, "select
customer.first_name as VOORNAAM,
customer.last_name as ACHTERNAAM,
substr(appointment.start_time,1,10) as DATUM,
substr(appointment.start_time,12,10) as STARTTIJD,
service_definitions.external_name as PRODUCT,
appointment.resource_name as AGENDA
from appointment
inner join appointment_customer on appointment.id = appointment_customer.appointmentjpa_id inner join customer on customer.id = appointment_customer.customerids
inner join appointment_service on appointment_service.appointment_id = appointment.id inner join service_definitions on service_definitions.id = appointment_service.service_id order by appointment.start_time asc ");
oci_execute($stid);
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo " < tr > \n ";
foreach ($row as $item)
{
echo "< td >" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "< /td >\n";
}
echo "< /tr >\n";
------------------ 已通过查询解决 -------------- --------------------
大家好,我通过在查询中添加以下内容解决了我的问题:
where substr(appointment.start_time,1,10) >= TO_CHAR(SYSDATE, 'YYYY-MM-DD')
@krishna 让我走上了正轨。我知道有更多更好的方法来处理这个问题,但对我来说它可以正常工作。
感谢大家的帮助。 问候 里奇
【问题讨论】:
标签: php arrays oracle date filter