PHP Week converted to date (last day) dates ("O-w") to y-m-d date--Post code

Source: Internet
Author: User
O-w Week converted to the last day of the normal date week public    function Weektodate ($oW) {        $oW = explode ("-", $oW);    Split o-w Zhou Weihin and weeks        $year = $oW [0];//year        $week = $oW [1];//week number        $weekYearBegin = Date ("W", Strtotime ($year. ") -01-01 "));   The beginning of January 1 is the day of the week, 0-6,0 is Sunday, 1-6 is Monday to Saturday        $WYearBegin = Date ("W", Strtotime ($year. " -01-01 "));  The beginning of January 1 is the first week of the year, which may be the start of the month: 01, or the last week of the past:        if ($WYearBegin = = "") {    //The first week of the year            $days = (7-$weekYearBegin)% 7 + (int) ($week-$WYearBegin) *7;  Need to calculate the last day of the week (Sunday), distance from the beginning of January 1 How many days        }else{  //last week of previous year            $days = (7-$weekYearBegin)%7 + (int) ($week) *7;  The last day of the week to be calculated (Sunday), the number of days from the beginning of January 1        }        $lastDayOfW = Date ("y-m-d", Strtotime ($year. " -01-01 + ". $days." Days "));  Because it is the last day (Sunday), it must fall in the year ($year), or the next year, and not fall in the previous year with $year +n days        return $lastDayOfW;    }

The above is implemented for the entire code, and returns the date ("y-m-d") of the Last Day (Sunday) of the week of the date ("O-w").

PHP Week converted to date (last day) dates ("O-w") to y-m-d date--Post 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.