只给出一个1到31之间的整数,我怎样才能得到"最后一天的日期" (意思是最后一次是在过去)?我正在寻找相当于strtotime("last Monday")
的月份,而不是strtotime("last 26th")
。
例如,如果我们假设今天是2018-06-04:
以下是我迄今为止所做的尝试:
if(intval(date("d"))>=$day)
echo date("Y-m-d",strtotime("first day of this month +$day days"));
else
echo date("Y-m-d",strtotime("first day of last month +$day days"));
答案 0 :(得分:0)
// we care about today
$d = date('d') ;
// the date you are checking for
$theDate = 3 ; // you will set this to whatever you want
// format the date
$useDate = (intval($theDate) < 10) ? '0' . $theDate : $theDate ;
// is it greater than today?
if (intval($theDate) > $d) {
// you want the previous month
$month = 'previous month' ;
} else {
// you want this month
$month = 'this month' ;
}
$result = date('Y-m-',strtotime($month)) . $useDate ;