douni1396 2012-03-24 17:17
浏览 8
已采纳

php - 比较时间戳日期以确保用户的年龄最小[重复]

Possible Duplicate:
How to calculate the difference between two dates using PHP?

When a user signs up the system has to check that they are old enough to do so, in this example they have to be atleast 8 years old

$minAge = strtotime(date("d")."-".date("m")."-".(date("Y")-8));
$dob = strtotime($day."-".$month."-".$year);

$minAge = 01-03-2004, $dob = 01-02-2011

I basically need to make sure this person was born before 2004 but I want to know whether I have to convert the timestamps to do a comparison or whether there is a more efficient way.

Any help is appreciated, thank you

  • 写回答

3条回答 默认 最新

  • dongque1958 2012-03-24 17:21
    关注

    With your $dob timestamp, you can subtract that from the current date's timestamp, and then balance those values versus your minAge. ex:

    if(($dob-time())=>$minAge) {
       //OVER 8 YEARS
    } else {
       //UNDER 8
    }
    

    Although, with this method you are comparing minage as a timestamp without days, hours, minutes or seconds, so keep that in mind when using the "time()" value as described in this example.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路