我遇到了有關事件日期的奇怪問題,並且我盡力使其得到解決,但無法完成。省略日期範圍列表中的冗餘月份和年份
我附上的我多麼想在頁面上顯示的日期的截圖:
在圖片中AKTION第一事件Deine科特布斯!是5個事件的組合,每個事件都有其開始日期和結束日期。
活動的第一部分是1日活動,活動從4月4日開始,到4月4日結束。第二部分同樣在4月7日,4月9日第3部分和4月20日第4部分
最後一部分從5月5日開始到5月10日結束。
日期以這種格式存儲在數據庫中: 我正在顯示事件的最後部分的日期。 活動開始日期:2013年5月5日00:00:00 活動結束日期:2013年5月10日00:00:00
所以我想顯示在圖片中顯示的日期格式。
有多種情況: 首先,如果所有日期都在一個月內發生,那麼我們只在最後一次顯示月份名稱。 二是如果月份發生變化,月份名稱將在月份更改日期之後顯示。
我在while循環中獲取事件日期,所以如何將當前事件日期與循環中即將到來的事件日期進行比較。
這是迄今爲止我已經習慣了從數據庫中獲取日期的代碼..
$nid = $row->nid;
$get_product_id = "SELECT product_id from {uc_product_kits} where nid='$nid'";
$res = db_query($get_product_id);
while ($get_product_id_array_value = db_fetch_array($res)) {
$prductid = $get_product_id_array_value['product_id'];
$start_date = db_query("select event_start,event_end from {event} where nid=%d",$prductid);
$start_date_value = db_fetch_object($start_date);
$end_value = $start_date_value->event_start;
$event_end_date = $start_date_value->event_end;
$TotalStart = date("d M Y", strtotime($end_value));
$TotalEnd = date("d M Y", strtotime($event_end_date));
$onlyMonthStart = date("M", strtotime($end_value));
$onlyMonthEnd = date("M", strtotime($event_end_date));
//$groupMonth = db_query("select event_start,event_end, month from {event} where nid=%d group by ",$prductid);
if($TotalStart == $TotalEnd){
$startDay = date("d", strtotime($end_value));
$startMonth = date("M", strtotime($end_value));
if(in_array($startMonth,$newMonth)) {
echo $onlstartdate;
}
else {
$onlstartdate = date("d", strtotime($end_value));
echo $onlstartdate;
$tempStorage[] = $startMonth
}
//$newMonth[] = $startMonth;
}
}
我已經更新了我的一些示例代碼的答案。 – 2013-04-18 09:44:33
謝謝馬丁。這對我有效。 – 2013-04-18 12:41:47
不客氣。快樂,它幫助你。 – 2013-04-18 12:46:52