はじめに phpで日付関連のこと調べると、手続き型の方法が検索上位に来てあまり手続き型で書きたくないなーと思ったので、DateTimeクラスを使った日付関連のことを個人メモ的にまとめた。 サンプル 現在日時を作成 $date = new DateTime(); echo $date->format('Y-m-d H:i:s'); // 2014-08-06 21:15:49 // 文字列から $date = new DateTime('2014-08-01 23:01:05'); echo $date->format('Y-m-d H:i:s'); // 2014-08-01 23:01:05 // 数値から $date = new DateTime(); $date->setDate(2014,8,1); echo $date->format('Y-m-d H:i:s'); // 201
Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Su
世間でも言われていますが、mysqlのtimestamp型はいろいろバッドノウハウの固まりではないかと思います。 最近はできるだけdatetime型にするようにしているのですが、すでにtimestamp型依存で動いているコードがある場合、alter tableするのも難しかったりします。 10.3.1. DATETIME、DATE、そして TIMESTAMP タイプや10.3.1.1. TIMESTAMP MySQL 4.1での性質 (いずれもMySQLマニュアル)にも諸々書いてありますが、気になるポイントは以下のあたり。 各テーブルの最初に現れるtimestamp型カラムは、明示的に更新をしていないとUPDATE, REPLACEで現在時刻に自動更新される 各テーブルの二つ目以降のtimestamp型カラムは自動更新されない 扱える期間が1970年~2037年である (datetime型
とある日が今から何日後? というのをPHPでやるならどうするのがいいんだろう そんな感じで調べていたらPHP による日付・時刻・時間の計算・演算のまとめ – hoge256ブログを見つけました これこれ、って思ったけどよくよく見てみるとちょっと情報が古いような、2007年の記事だし・・・ という訳でちょっと書き直してみました 現在時刻の取得 echo date('Y-m-d H:i:s'); $date = new DateTime(); echo $date->format('Y-m-d H:i:s'); 日付/時刻のパース 日付/時刻を表したある書式の文字列から、年、月、日、時、分、秒を取得します echo date('Y-m-d H:i:s', strtotime('2011-08-12 10:35:20')); $date = new DateTime('2011-08-12 10
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く