douwa0280 2011-11-07 19:52
浏览 31
已采纳

php strtotime和锻炼多年?

I have a date stored in my mysql database and I can workout the days since the date like so,

 ceil(time() - strtotime($account['joined']) / 60 / 60 / 24 % 365);

But how can I work out the years, since years is the highest format of time, since after that it is millenia and such?

The variable is one such as:

2011-10-06 22:01:57

Thanks

  • 写回答

4条回答 默认 最新

  • dougan4663 2011-11-07 19:57
    关注

    Use date("Y")

    <?php 
    $time = strtotime("1 Jan 2001 1:11:11"); 
    echo "Years since time: ".(date("Y") - date("Y", $time));
    

    http://sandbox.phpcode.eu/g/220fe/1

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

报告相同问题?

悬赏问题

  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用