Skip to content

Instantly share code, notes, and snippets.

@brtriver
Created March 30, 2012 01:20
Show Gist options
  • Save brtriver/2245531 to your computer and use it in GitHub Desktop.
Save brtriver/2245531 to your computer and use it in GitHub Desktop.
What result do you expect?
<?php
date_default_timezone_set('Asia/Tokyo');
if (date('n', strtotime('this month')) === date('n', strtotime('last month'))) {
echo "never call";
}
// last month は前月の"同一日"を返そうとするので、
// 2月30日 -> 3月1日 のように解釈されてしまう。
// 前月の月を知りたい場合は 以下のようにfirst day of をつけないと先月が何月かを正確に取得できない!
$last_month = date('n', strtotime('first day of last month'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment