2007/8/27 月曜日

日付処理

カテゴリー: PHP, program — hot @ 23:33:51

日付処理の覚書

PHPの日付計算
$date = date(‘Y-m-d’,strtotime(“-1 day”)); // 一日前
$date = date(‘Y-m-d’,strtotime(“-1 month”)); // 一ヶ月前
$date = date(‘Y-m-d’,strtotime(“-1 year”)); // 一年前

PostgreSQLの日付
hogeテーブルのdateカラムに以下のような値が入っている場合
2007-08-27 22:12:10.109

select to_date(to_char(date, ‘Mon YYYY’),’Mon YYYY’) from hoge;
→2007-08-01
select to_date(to_char(date, ‘YYYY’),’YYYY’) from hoge;
→2007-01-01

よく使うのに忘れるので・・・・

コメントはまだありません »

コメントはまだありません。

このコメント欄の RSS フィード トラックバック URL

コメントをどうぞ

Copyright (C) 2007-2010 HOTSYSTEMS