dongshuo1257 2014-11-17 10:30
浏览 71
已采纳

将日期与日和月比较显示错误输出

I want to compare, whether a date is bigger then the current date. With day and month!

If I only compare to month i got this output, which is correct:

Chichiri : 08.11.2014 Rokno2h : 14.11.2014 Sasch79_AUT : 29.11.2014 Sonny : 08.12.2014 Marek : 31.12.2014 Fuchs : 31.12.2014 hauni89 : 31.12.2014 RIX1287 : 31.12.2014

But I want to compare to day and month, so that the first two doen't appear in the list, because their birthdays are over. But I got the following output then:

haislpunk : 29.03.2014 Vastl : 19.04.2014 Luckypunch10 : 22.04.2014 DaveMetz : 25.04.2014 Ghoost : 24.06.2014 RoxoriO_AUT : 18.08.2014 Alchemagi : 21.08.2014 Shizophren83 : 29.08.2014 FatePhoenix : 29.09.2014 Testaccount : 21.10.2014 wernoid : 23.10.2014 bAc-Maus : 25.10.2014 Ginibal : 25.10.2014 CrySix1992 : 28.10.2014 Sasch79_AUT : 29.11.2014 Marek : 31.12.2014 Fuchs : 31.12.2014 hauni89 : 31.12.2014 RIX1287 : 31.12.2014

Here is my code with date('d.m') which doesn't work. With date ('m') is worked with month:

    while($row = mysql_fetch_array($test_result)){
    $curr_date = date('d.m');   
    $date = $row['value'];
    $dateFormatted = date('d.m', strtotime($date));
    //echo $dateFormatted . ' *** ' . $curr_date . '<br>';
    //wenn Geburtsmonat > aktueller Monat dann anzeigen! sonst nicht!
    if($dateFormatted >= $curr_date){
        echo $row['username'] . ' : ';
        echo date('d.m.', strtotime($date)) . date('Y');
        echo '<br />'; 

    }
}

I have to convert the date from database, because it is saved as a text type in the database. I solved this problem in this related question. Mysql Text to Date won't work

  • 写回答

2条回答 默认 最新

  • dou47278 2014-11-17 10:38
    关注

    Wrong comparison, should compare in format 'm.d', not 'd.m' (you compare strings).

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

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能