×

Sign in with twitter.

You can follow the user and hashtags.

Share your tips on social media.

Post relative tips.

If you have relative tips, click [Add relative tips] to post.

DBのdatetimeの値と現在時刻の差が何日かるか調べるPHPコード

@cakephper@cakephper 2054 viewer 51 embed viewer embed
PHP5.3以上です。
参考
http://jp.php.net/manual/ja/class.dateinterval.php


$modified = '2012-02-13 17:14:46';
$date = DateTime::createFromFormat('Y-m-d H:i:s', $modified);
$now = new DateTime();
$interval = $date->diff($now);
$daysAgo = $interval->format('%a');

echo $daysAgo . "日間";

#php

Click this to change format.

Add relative tips

Users who share this tip.

Comments