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

Source: Internet
Author: User
Tags learn php

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:

?
12345678910111213141516171819202122 <?phpheader("Content-type:text/html;charset=utf-8");date_default_timezone_set("Asia/Shanghai");$year = (int)$_GET[‘year‘];$week = (int)$_GET[‘week‘];$weeks = date("W", mktime(0, 0, 0, 12, 28, $year));echo $year . ‘年一共有‘ . $weeks . ‘周<br />‘;if ($week > $weeks || $week <= 0){ $week = 1;}if ($week < 10){ $week = ‘0‘ . $week;}$timestamp[‘start‘] = strtotime($year . ‘W‘ . $week);$timestamp[‘end‘] = strtotime(‘+1 week -1 day‘, $timestamp[‘start‘]);echo $year . ‘年第‘ . $week . ‘周开始时间戳:‘ . $timestamp[‘start‘] . ‘<br />‘;echo $year . ‘年第‘ . $week . ‘周结束时间戳:‘ . $timestamp[‘end‘] . ‘<br />‘;echo $year . ‘年第‘ . $week . ‘周开始日期:‘ . date("Y-m-d", $timestamp[‘start‘]) . ‘<br />‘;echo $year . ‘年第‘ . $week . ‘周结束日期:‘ . date("Y-m-d", $timestamp[‘end‘]);?>

Code two:

?
12345678910111213141516171819202122 <?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 = date(‘d-m-Y‘, strtotime(‘this week sunday‘, $custom_date)); $week_array[0] = $week_start; $week_array[1] = $week_end; return $week_array;}echo ‘<br> Weeks in 2013<br>‘ . getIsoWeeksInYear(2013);$weekday = weekday(strtotime(date(‘d-m-Y‘, strtotime(‘5-8-2013‘))));echo ‘<br> 10-8-2013‘;echo ‘<br>Start: ‘ . $weekday[0];echo ‘<br>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.

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

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.