PHP implementation of the week X conversion timestamp function

Source: Internet
Author: User
Tags echo date
Do an animation station, to achieve a weekly update list, respectively, by the Week 1 to Sunday to pull data.
Wrote a function to implement the key functions.
  1. function Gettimefromweek ($dayNum) {
  2. $dayNum: 0-6
  3. $curDayNum =date ("w");
  4. if ($dayNum > $curDayNum) $timeFlag = "Last";
  5. ElseIf ($dayNum = = $curDayNum) $timeFlag = "";
  6. If this week x is not available, use this week's week x else $timeFlag = "Next";
  7. else $timeFlag = "last";//this week X is not reached by the week of Week X (let data not be empty)
  8. $arryWeekDay = Array (' Sunday ', ' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday ');
  9. $timeStamp =strtotime ("$timeFlag". " $arryWeekDay [$dayNum] ");
  10. return $timeStamp;
  11. }
  12. echo Date ("Y-m-d L", Gettimefromweek (0)); echo "
    ";
  13. echo Date ("Y-m-d L", Gettimefromweek (1)); echo "
    ";
  14. echo Date ("Y-m-d L", Gettimefromweek (2)); echo "
    ";
  15. echo Date ("Y-m-d L", Gettimefromweek (3)); echo "
    ";
  16. echo Date ("Y-m-d L", Gettimefromweek (4)); echo "
    ";
  17. echo Date ("Y-m-d L", Gettimefromweek (5)); echo "
    ";
  18. echo Date ("Y-m-d L", Gettimefromweek (6)); echo "
    ";
Copy Code
  • 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.