如何计算日期时间字段的差异,现在在PHP? [英] How to calculate the difference of datetime field and now in PHP?

查看:148
本文介绍了如何计算日期时间字段的差异,现在在PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个包含以下信息的datetime字段:

I have a datetime field in my database that contains the following information:

2012-05-03 17:34:01

我想检查datetime字段和现在之间的区别:

I want to check the difference between the datetime field and now:

$now = date("Y-m-d H:i:s");

我试图弄清现在和写入数据库字段的时间已经过去了几天

I am attempting to work out how many days have passed between now and the time written to the database field.

如何实现?

推荐答案

答案:)

$date = new DateTime("2012-05-03 17:34:01");
$now = new DateTime();

echo $date->diff($now)->format("%d days, %h hours and %i minuts");

这篇关于如何计算日期时间字段的差异,现在在PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆