Php ';圆形';把日期推迟到下个月初
我需要从一个变量中获取一个现有日期,并显示一个日期,该日期始终是下个月的第一天(01)(同时也要考虑该年) 如果我有这个:Php ';圆形';把日期推迟到下个月初,php,date,Php,Date,我需要从一个变量中获取一个现有日期,并显示一个日期,该日期始终是下个月的第一天(01)(同时也要考虑该年) 如果我有这个: $date = '2017-03-17'; // YYYY-MM-DD 我需要将该日期作为输出: 2017-04-01 // The first day of the next month 只是另一个例子 $date = '2017-12-23'; // YYYY-MM-DD …应转换为 2018-01-01 // The first day of the next
$date = '2017-03-17'; // YYYY-MM-DD
我需要将该日期作为输出:
2017-04-01 // The first day of the next month
只是另一个例子
$date = '2017-12-23'; // YYYY-MM-DD
…应转换为
2018-01-01 // The first day of the next month
只需将日期增加
1
month,然后将日期设置为1
st。做-
date('Y-m-01', strtotime('+1 MONTH', strtotime($date)));
只需将日期增加
1
个月,然后将日期设置为1
st个月。做-
date('Y-m-01', strtotime('+1 MONTH', strtotime($date)));
您可以使用日期时间,如:
$dateTime = new DateTime('2017-03-17');
$dateTime->modify('first day of next month');
echo $dateTime->format('Y-m-d');
您可以使用DateTime,如:
$dateTime = new DateTime('2017-03-17');
$dateTime->modify('first day of next month');
echo $dateTime->format('Y-m-d');
你可以使用
$date = '2017-03-17';
echo date('Y-m-01', strtotime('+1 month',strtotime($date)));
您可以使用
$date = '2017-03-17';
echo date('Y-m-01', strtotime('+1 month',strtotime($date)));
我认为这可能已经被问到并回答了@PhilS,但我认为@Matei Mihai answer比正确答案好得多。我认为这可能已经被问到并回答了@PhilS,但我认为@Matei Mihai answer比正确答案好得多。另一个选项的可能重复做同样的事情。+1.)让它看起来如此有趣+1另一种选择也可以这样做。+1.)为了让它看起来如此有趣+1由@Sougata Bosecheck在下面发布的相同答案早前发布的时间由@Sougata Bosecheck在下面发布的相同答案早前发布的时间