PHP: how to obtain weekly information of a month

Source: Internet
Author: User
This article mainly introduces how to use PHP to obtain weekly information of a certain month. It involves the related computing skills of php for date and time. It has some reference value. For more information, see

This article mainly introduces how to use PHP to obtain weekly information of a certain month. It involves the related computing skills of php for date and time. It has some reference value. For more information, see

This example describes how to obtain the weekly information of a month in PHP. Share it with you for your reference. The details are as follows:

<? Php function getMonthweeks ($ date) {$ ret = array (); $ stimestamp = strtotime ($ date); $ mdays = date ('T', $ stimestamp ); $ msdate = date ('Y-m-d', $ stimestamp); $ medate = date ('Y-m -'. $ mdays, $ stimestamp); $ etimestamp = strtotime ($ medate); // week returns the first week $ zcsy = 6-date ('w', $ stimestamp ); // The first day of the week is also removed from the first day. $ zcs1 = $ msdate; $ zce1 = date ('Y-m-d', strtotime ("+ $ zcsy day ", $ stimestamp); $ ret [1] = "week 1st ". $ zcs1 .'~ '. $ Zce1; // obtain the number of times in the middle of the week $ jzc = 0; // The number of times in the previous month is 6 weeks or 5 weeks. $ jzc0 = ""; $ jzc6 = ""; for ($ I = $ stimestamp; $ I <= $ etimestamp; $ I ++ = 86400) {if (date ('w', $ I) = 0) {$ jzc0 ++;} if (date ('w', $ I) = 6) {$ jzc6 ++ ;}} if ($ jzc0 = 5 & $ jzc6 = 5) {$ jzc = 5;} else {$ jzc = 4;} date_default_timezone_set ('prc '); $ t = strtotime ('+ 1 Monday '. $ msdate); $ n = 1; for ($ n = 1; $ n <$ jzc; $ n ++) {$ B = strtotime ("+ $ n week-1 week", $ t); $ dsdate = date ("Y-m-d ", Strtotime ("-1 day", $ B); $ dedate = date ("Y-m-d", strtotime ("5 day", $ B )); $ jzcz = $ n + 1; $ ret [$ jzcz] = "th ". $ jzcz. "Week ". $ dsdate. '~ '. $ Dedate;} // obtain the last week's $ zcsy = date ('w', $ etimestamp); // The last week is the week's day ~ Six 0 ~ 6 $ zcs1 = date ('Y-m-d', strtotime ("-$ zcsy day", $ etimestamp); $ zce1 = $ medate; $ jzcz = $ jzc + 1; $ ret [$ jzcz] = "th ". $ jzcz. "Week ". $ zcs1 .'~ '. $ Zce1; return $ ret;} $ ret = getMonthweeks ('2017-12-01 '); for ($ I = 0; $ I <= count ($ ret ); $ I ++) {echo @ $ ret [$ I]."
";}?>

The running result is as follows:

1st ~ 2012-12-01
2nd ~ 2012-8 8
3rd ~ 2014-10-15
WEEK 1, 4th-16 ~ 2012-12-22
WEEK 1, 5th ~ 2012-12-29
WEEK 1, 6th ~ 2012-12-31

I hope this article will help you with php programming.

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.