Re: [请益] 请教一个日期条件设计问题

楼主: gpmm (银色)   2018-01-23 07:51:21
※ 引述《lusaka (gary.lusifa)》之铭言:
: kyoe大大您好
: 感谢您提供您提供思路,但是显示的结果如下:
: $start_date = 1970-01-01
: $end_date = 1970-01-01
其实看没有很懂到底想做什么 XDD
# 按原题,生日为 1911-01-03,
$birthday = '1911-01-03';
$birthdayTime = strtotime ($birthday);
如果把生日年假定为统一计算的年度,那么
$startDate = date ("Y-m-01", strtotime ("-1 month", $birthdayTime));
// $startDate = 1910-12-01
$endDate =
date ("Y-m-d", strtotime ("last day of this month", $birthdayTime));
// $endDate = 1911-01-31
或是你不要用描述语法的话,直接用 t 取月日数
$endDate = date ("Y-m-t", $birthdayTime);
// $endDate = 1911-01-31
不过其实你真的需要的只是月的判断吧?
生日在 1 月,那就用 12 和 1 两个月数字来比对就好啦
XD

Links booklink

Contact Us: admin [ a t ] ucptt.com