doushi1510 2016-03-04 01:57
浏览 27

使用php检索不同年份

Sorry, I am very new to PHP. I searched for similar problems on Google, but they say it should be no problem if using PHP version 5.2+. I don't know what version that I am using right now. The error message shows like this:

Fatal error: Call to undefined method DateTime::diff() in line 3 at $interval

If I comment-out lines 3 and 4, it can run, but can't retrieve a different date. I only want the year only. Can someone help me figure out what the problem is? Thanks in advance.

$date1 = new DateTime("$bday"); 
$date2 = new DateTime("now"); 
$interval = $date1->diff($date2); 
$diff = $interval->format('%y-%m-%d'); 
$dif2 = explode("-",$diff);

$umur = $dif2[0];
if($umur < 10){ $catumur = 1; }
if(($umur > 9)&&($umur < 20)){ $catumur = 2; }
if(($umur > 19)&&($umur < 60)){ $catumur = 3; }
if($umur > 59){ $catumur = 4; }
  • 写回答

1条回答 默认 最新

  • douh9817 2016-03-04 02:11
    关注

    There is no problem in your code. To check the version of your PHP, Create a php file and inside it, use phpinfo(). Run it and it will show all the details of your PHP.

    <?php
        phpinfo();
    

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)