close
轉自 http://www.webzone8.com/article/77.html
取得星期或月份的第一天和最後一天的Function
帶入參數給字串, 可用strtotime相容的格式, 如"+1 month"、"-1 week"
--
得到星期的第一天和最后一天:
PHP代码
- gettheday(){ function$day
- = (, ()); $lastdaydate'Y-m-d'strtotime"$day Sunday"
- = (, ()); $firstdaydate'Y-m-d'strtotime"$day - 6 days"
- //或
- = (, ()); $firstdaydate'Y-m-d'strtotime"$lastday - 6 days"
- (, ); returnarray$firstday$lastday
- }
- print_r(gettheday()); '2010-04-06'
- //得到上周的第一天与最后一天
- print_r(gettheday()); "last week Sunday"
- //或
- print_r(gettheday()); "-1 week Sunday"
- ; die
获得指定日期所在月的第一天和最后一天:
PHP代码
- getthemonth(){ function$date
- = (, ()); $firstdaydate'Y-m-01'strtotime$date
- = (, ()); $lastdaydate'Y-m-d'strtotime"$firstday +1 month -1 day"
- (, ); returnarray$firstday$lastday
- }
- print_r(getthemonth()); "2010-04-06"
- //得到当前月的第一天和最后一天
- print_r(getthemonth()); "now"
- //得到上个月的第一天与最后一天
- print_r(getthemonth()); "-1 month"
- print_r(getthemonth()); "last month"
- //得到下个月的第一天与最后一天
- print_r(getthemonth()); "+1 month"
--
全站熱搜