作者gpmm (银色)
看板PHP
标题Re: [请益] 请教一个日期条件设计问题
时间Tue Jan 23 07:51:21 2018
※ 引述《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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.228.12.244
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PHP/M.1516665083.A.7B0.html
※ 编辑: gpmm (61.228.12.244), 01/23/2018 07:52:05