Created
February 7, 2013 02:52
-
-
Save mamor/4728011 to your computer and use it in GitHub Desktop.
指定月にN月加算/減算して、その初日/末日を取得するメソッド
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get first day on target month | |
* | |
* @param string $yyyymm | |
* @param int $add_month | |
* @param string $fmt | |
* @return string | |
*/ | |
public static function get_first_day($yyyymm = null, $add_month = 0, $fmt = 'Y-m-d') | |
{ | |
! $yyyymm and $yyyymm = date('Ym'); | |
$date = date_create($yyyymm.'01'); | |
date_add($date, date_interval_create_from_date_string($add_month.' month')); | |
return date_format($date, $fmt); | |
} | |
/** | |
* Get last day on target month | |
* | |
* @param string $yyyymm | |
* @param int $add_month | |
* @param string $fmt | |
* @return string | |
*/ | |
public static function get_last_day($yyyymm = null, $add_month = 0, $fmt = 'Y-m-d') | |
{ | |
! $yyyymm and $yyyymm = date('Ym'); | |
$date = date_create($yyyymm.'01'); | |
date_add($date, date_interval_create_from_date_string(($add_month + 1).' month')); | |
date_sub($date, date_interval_create_from_date_string('1 day')); | |
return date_format($date, $fmt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment