douwen5741 2012-04-01 08: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 :)

 $get_courses = "SELECT 
     courses.course_id, 
     DATE_FORMAT(courses.date_added,'%a %b %e %Y') as formatted_date_added, 
     courses.course_type, 
     courses.start_date, 
     location_name, 
     price, 
     duration 
 FROM courses 
 JOIN addresses ON courses.course_get_address_id = addresses.address_id 
 WHERE courses.active = 'Active' 
 ORDER BY courses.date_added DESC 
 LIMIT 30";

XML

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

3条回答 默认 最新

  • dongpin2969 2012-04-01 09: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条)

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动