6月 212012
 

php5.3では、DateTimeクラスを使った日付の計算ができる。
//本日
$today = new DateTime();
echo $today->format(‘Y-m-d’);
//もととなる日付
$release = new DateTime(‘20120619’);
$diff = $release->diff($today);
echo $diff->format(‘%a’);
//差
$diff_d = $diff->format(‘%a’);
echo $diff_d;
*Windows版のphp5.3.5などのバージョンだと、DateTime::diff()で日付の差が6015になるバグが報告されています。バージョンアップするしかないです。
http://bugs.php.net/bug.php?id=51184

よく読まれている記事

この記事を読んだ人は次の記事も読んでいます:

このエントリーをはてなブックマークに追加
はてなブックマーク - DateTimeを使った日付の差
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)