简体   繁体   English

在PHP中获取最近的日期

[英]Get Nearest Date in php

I have list of events so each event start date to end date so each event have list of schedules between events start date and end date I need to get only first nearest date I mean first event schedule date. 我有事件列表,所以每个事件的开始日期到结束日期,所以每个事件都有事件开始日期和结束日期之间的时间表列表。我只需要获取第一个最近的日期,即第一个事件时间表的日期。

Here is my code 这是我的代码

SELECT
  s.schedule_id, s.schedule_start_time, s.schedule_end_time, s.schedule_topic, s.Parallel,
  c.speaker_name
FROM schedule_table AS s, speaker_profile_table AS c
WHERE
  s.event_id='23'
  OR s.schedule_date LIKE '%2012-06-07%'
  AND c.speaker_id = s.speaker_id
ORDER BY s.schedule_start_time ASC

Here I get all schedules like this 在这里,我得到了所有这样的时间表

schedule1:2012-06-06, schedule2:2012-06-06, schedule3:2012-06-08 时间表1:2012-06-06,时间表2:2012-06-06,时间表3:2012-06-08

Here I need only schedule1 and schedule2 only I don't need schedule3 how can i get this please guide me 在这里,我只需要schedule1和schedule2我就不需要schedule3我怎么能得到这个,请指导我

Thanks for advance 谢谢前进

If I understand what you want correctly, this should do the job ( EDITED ): 如果我正确理解了您想要的内容,则应该执行此操作( EDITED ):

SELECT
  s.schedule_id, s.schedule_start_time, s.schedule_end_time, s.schedule_topic, s.Parallel,
  c.speaker_name
FROM schedule_table s
LEFT JOIN speaker_profile_table c ON c.speaker_id = s.speaker_id
WHERE s.schedule_date = (
  SELECT schedule_date
  FROM schedule_table
  WHERE
    event_id = '23'
    OR schedule_date LIKE '%2012-06-07%'
  ORDER BY schedule_date ASC
  LIMIT 1
)
ORDER BY s.schedule_start_time ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM