1
OK ...所以我有一個日曆,在使用CodeIgniter構建的自定義PHP應用程序中,該應用程序從MySQL數據庫中提取條目。在包含條目數據的表格中,有3個字段管理條目的日期(start_date),時間(start_time)和持續時間(持續時間)。現在,隨着最終用戶將條目移動到新的日期和/或時間,系統需要針對這三個字段檢查是否存在任何時間表衝突。檢查日期/時間衝突MySQL
以下是查詢中使用的一些增值經銷商:
$request_entry_id // the id of the entry being moved
$request_start_date // the requested new date
$request_start_time // the requested new time
$request_duration // the duration of the entry being moved (will remain the same)
$end_time = ($request_start_time + $request_duration); // the new end time of the entry being moved
用於檢查時間衝突我的查詢是:
SELECT t.id
FROM TABLE t
WHERE t.start_date = '$request_start_date'
AND (j.start_time BETWEEN '$request_start_time' AND '$end_time'))
AND t.id <> $request_entry_id
上面的查詢將檢查是在開始的任何條目與請求相同的日期和時間。但是,我也想檢查一下,確保新請求不在現有條目的持續時間內,以最有效的方式(有訣竅)。有什麼建議麼?提前致謝!
這將做工精美。但是,我應該提到的持續時間字段是一個以十進制格式表示小時的字段(例如,1.50是一個半小時)。如果可以的話,我是否仍然可以通過轉換使用addtime,例如1.50到01:30:00? – user2220551
你可以用'SEC_TO_TIME(3600 * 1.5)'將'1.5'轉換成'01:30'。 – Joni
這就是票。謝謝。 :) – user2220551