PHP gets a few weeks a year and a weekly start date and end date, weeks start date _php Tutorial

Source: Internet
Author: User
Tags learn php

PHP gets a few weeks a year and a weekly start date and end date, a few weeks start date


Recently, a project was taken, with one requirement being PHP to get a few weeks a year and a weekly start date and contact date. Find some information on the Internet is not appropriate, so I made a copy, the following two ways to achieve PHP to obtain a few weeks a year and a weekly start date and end date

Code One:

<?phpheader ("Content-type:text/html;charset=utf-8");d ate_default_timezone_set ("Asia/shanghai"); $year = (int) $ _get[' year '; $week = (int) $_get[' Week '); $weeks = Date ("W", mktime (0, 0, 0, $year)); Echo $year. ' A total of years '. $weeks. ' Week
' If ($week > $weeks | | $week <= 0) {$week = 1;} if ($week <) {$week = ' 0 '. $week;} $timestamp [' start '] = Strtotime ($year. ' W '. $week); $timestamp [' end '] = Strtotime (' +1 week-1 Day ', $timestamp [' Start ']); Echo $year. ' Year of the first '. $week. ' Week start timestamp: '. $timestamp [' Start ']. '
'; Echo $year. ' Year of the first '. $week. ' Week end timestamp: '. $timestamp [' End ']. '
'; Echo $year. ' Year of the first '. $week. ' Week start date: '. Date ("y-m-d", $timestamp [' Start ']). '
'; Echo $year. ' Year of the first '. $week. ' Week End Date: '. Date ("y-m-d", $timestamp [' End ']); >

Code two:

<?phpheader ("content-type:text/html;charset=utf-8"); function Getisoweeksinyear ($year) {$date = new DateTime; $ Date->setisodate ($year, 53); Return ($date->format ("W") = = = = "53"? 53:52);} Function Weekday ($custom _date) {$week _start = date (' D-m-y ', strtotime (' This week Monday ', $custom _date)); $week _end = Dat E (' D-m-y ', strtotime (' This week Sunday ', $custom _date)); $week _array[0] = $week _start; $week _array[1] = $week _end; return $week _array;} Echo '
Weeks in 2013
' . Getisoweeksinyear, $weekday = Weekday (Strtotime (' D-m-y ', strtotime (' 5-8-2013 '))), Echo '
10-8-2013 '; Echo '
Start: '. $weekday [0];echo '
End: '. $weekday [1];? >

All of the above, I hope to learn PHP for you to get a few weeks a year and a weekly start date and end date, helpful.

http://www.bkjia.com/PHPjc/1044256.html www.bkjia.com true http://www.bkjia.com/PHPjc/1044256.html techarticle PHP Gets a few weeks in a year and a weekly start date and end date, a few weeks from the start date of a recent project, and one of the requirements is to get a year with PHP for a few weeks and a weekly start date ...

  • Related Article

    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.