douwen5741 2012-04-01 00:38
浏览 38
已采纳

从<pubDate> PHP RSS提要中删除时间

I have records with no time attached so, with the rss feed I'm just getting 00:00.

I need help customizing this code to remove the time but, keep the date.

Any help would be great as I have been playing with this for fat too long :)

  1. $get_courses = "SELECT
  2. courses.course_id,
  3. DATE_FORMAT(courses.date_added,'%a %b %e %Y') as formatted_date_added,
  4. courses.course_type,
  5. courses.start_date,
  6. location_name,
  7. price,
  8. duration
  9. FROM courses
  10. JOIN addresses ON courses.course_get_address_id = addresses.address_id
  11. WHERE courses.active = 'Active'
  12. ORDER BY courses.date_added DESC
  13. LIMIT 30";

XML

 '<pubDate>'.$course['formatted_date_added'].' GMT</pubDate>'
  • 写回答

3条回答 默认 最新

  • dongpin2969 2012-04-01 01:47
    关注

    Change

    DATE_FORMAT(courses.date_added,'%a %b %e %Y') as formatted_date_added
    

    to

    UNIX_TIMESTAMP(courses.date_added) as formatted_date_added
    

    and in PHP:

    if (date("H:i", $tuple["when"]) == "00:00")
        // without time
        echo '<pubDate>'.strftime('%a %b %e %Y', 
            $course['formatted_date_added']).' GMT</pubDate>';
    else
        // with time
        echo '<pubDate>'.strftime('%a %b %e %Y %r', 
            $course['formatted_date_added']).' GMT</pubDate>';
    

    Or just output

    '<pubDate>'.strftime('%a %b %e %Y', $course['formatted_date_added']).' GMT</pubDate>'
    

    if you won't ever have time information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部