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条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题