【PHP】日時・時間 (date / time) について

時間を好きなフォーマットに出力させるには...

サンプル1

$before = "2007-02-28 01:55:59";

$after = date("H:i", strtotime($before));

参考資料

http://chibinowa.net/notebook/php/97.html
http://php.plus-server.net/function.date.html

サンプル2

$before = "2007-02-28 01:55:59";

$date = new DateTime($before);
$after = $date->format('Y.m.d');

現在時刻の取得

サンプル

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

参考資料

http://www.hoge256.net/2007/08/63.html

その月の初日/末日

サンプル

$year = 2011;
$month= 7;

// その月の初日
$firstDate = date("Y-m-d", mktime(0, 0, 0, $month, 1, $year));
// その月の末日
$lastDate = date("Y-m-d", mktime(0, 0, 0, $month + 1, 0, $year));