タグ

2014年12月4日のブックマーク (2件)

  • PHP strtotime関数でハマった!(翌月の表現の処理) - Web Tech Log by 1KB

    Web開発、WebデザインSEO、携帯コンテンツなどWebにまつわるテクノロジーを追っかけるブログ。旧名「Web屋に復帰した人間のリハビリ日記」 PHPには strtotimeという関数があります。引数に例えば「+1 month」と指定すれば1ヶ月後のタイムスタンプを返してくれます。 <?php $nextmanth = date("Y-m", strtotime("+1 month"));?> で翌月を返してくれると思ってました。しかし甘かった!! 例えば今月28日の時点では問題なかったのですが、 例:2009年1月28日の時点 <?php $nextmonth = date("Y-m", strtotime("+1 month")); echo $nextmonth;?> 結果:2009-02 これが31日では 例:2009年1月31日の時点 <?php $nextmonth = d

  • PHP 日付の計算(加算、減算)

    PHPでの日付の計算(加算、減算)でーす。 使うのはこちら↓↓ strtotime関数 int strtotime ( string 英文字の日時 [, int 日付]) ※「int 日付」は初期値がnow(現在) これを使うと日、週、月、年の加算、減算が簡単に計算できます。 時・分・秒の加算、減算もできます。 「英文字の日時」の部分は加算、減算したい単位を設定。 day、week、month、year、hour、minute、second等。 ちなみに now は現在の時間です。 使い方はこんな感じ。 print "昨日:" . date("Y/m/d",strtotime("-1 day" ,strtotime(now))) . "<BR>"; print "今日:" . date("Y/m/d",strtotime("now")) . "<BR>"; print "明日:" . da