Two methods for retrieving PHP time excluding Saturday and Sunday

Source: Internet
Author: User
This article mainly introduces two methods for obtaining PHP time to exclude Saturday and Sunday, for more information about how to obtain a timestamp after 10 days, we can share with you today. The key to the program is that it does not count as Saturday. If you have other requirements. It can be changed to N days. It's not Saturday. Haha.

// Method 1: <? Php $ now = time (); // specify the date usage $ now = strtotime ('2017-01-08 '); $ day = 2014*24; $ total = 12; $ days = array (); for ($ I = 2; $ I <$ total; $ I ++) {$ timer = $ now + $ day * $ I; $ num = date ("N", $ timer)-2; // if ($ num >=- 1 and $ num <= 3) starting on Monday) {if (count ($ days)> = 10) break; $ days [] = date ("Y-m-d", $ now + $ day * $ I ); $ total + = 1; // $ total = 12? $ Total + 1: $ total;} else {$ total = 12? $ Total + 1: $ total ;} I I = 1; foreach ($ days as $ day) {echo "$ I ==> ". $ day. "\ n"; $ I ++;} // Method 2: function get_days ($ date = "") {$ now = empty ($ date )? Time (): strtotime ($ date); $ days = array (); $ I = 2; while (count ($ days) <10) {$ timer = $ now + 3600*24 * $ I; $ num = date ("N", $ timer)-2; // if ($ num >=- 1 and $ num <= 3) {$ days [] = date ("Y-m-d ", $ now + 3600*24 * $ I);} $ I ++;} return $ days ;}

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.