search
LoginSignup
29

More than 5 years have passed since last update.

posted at

updated at

【PHP】月末・月初の出力方法

今月の月初

echo date("Y-m-01", time());

今月の月末

echo date("Y-m-t", time());

前月の月初

/* echo date("Y-m-01",strtotime("-1 month")); */
訂正
$now = strtotime("2013-07-31");
echo date("Y-m-d",strtotime("first day of - 1 month",$now));

前月の月末

/* echo date("Y-m-t",strtotime("-1 month")); */
訂正
$now = strtotime("2013-07-31");
echo date("Y-m-d",strtotime("last day of - 1 month",$now));

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
29