Share 3 php get Calendar function _php Tips

Source: Internet
Author: User

The

Provides a date that gets the calendar list for the week of this date, and the key is the week mark

$month _date = ' 2015-09-25 ';
$start _time = strtotime ($month _date);
$start _week = Date (' W ', $start _time);
 
$total _month_day = date (' t ', $start _time);
 
$weeks _in_month = ceil ($start _week+ $total _month_day)/7);
$month _day_arr = [];
$start _month_day = 1;
      For ($i =0 $i < $weeks _in_month $i + +) {for ($j =0; $j <7; $j + +) {if ($i ==0 && $j >= $start _week) {
      $month _day_arr[$i] [$j] = $start _month_day;
    $start _month_day++;
    } elseif ($i = = 0) {$month _day_arr[$i] [$j] = ';
      else {$month _day_arr[$i] [$j] = $start _month_day;
    $start _month_day++;
    } if ($start _month_day > $total _month_day) {break;
}} echo "<pre>";
 
Print_r ($month _day_arr);
      Array ([0] => Array ([0] => [1] => [2] => 1 [3] => 2 [4] => 3
      [5] => 4 [6] => 5) [1] => Array ([0] => 6 [1] => 7 [2] => 8
[3] => 9 [4] => 10      [5] => [6] => [2] => Array ([0] => [1] => [2] =&gt ; [3] => [4] => [5] => [6] =>) [3] => Array ([0] =
    > [1] => [2] => [3] => [4] => [5] => [6] => 26
 ) [4] => Array ([0] => [1] => [2] => [3] => 30))

Gets the start date and end date of the month on which the specified date is located

/**
   * @param string $date
   * @param Boolean to True returns the start date, otherwise returns the end date
   * @return Array
   * @access Private
   * *
  Private Function Getmonthrange ($date, $returnFirstDay = True) {
    $timestamp = Strtotime ($date);
    if ($returnFirstDay) {
      $monthFirstDay = date (' Y-m-1 00:00:00 ', $timestamp);
      return $monthFirstDay;
    } else {
      $mdays = date (' t ', $timestamp);
      $monthLastDay = Date (' y-m-'. $mdays. ' 23:59:59 ', $timestamp);
      return $monthLastDay;
    }
  

Gets the date range for the current week, which is the date range from Monday to Sunday.

  function Getweekrange ($date) {$ret =array ();
  $timestamp =strtotime ($date);
  $w =strftime ('%u ', $timestamp);
  $ret [' Sdate ']=date (' y-m-d 00:00:00 ', $timestamp-($w-1) *86400);
  $ret [' Edate ']=date (' y-m-d 23:59:59 ', $timestamp + (7-$w) *86400);
  return $ret;
  //author:zhxia gets the start date and end Date function Getmonthrange ($date) {$ret =array () of the month on which the specified date is located;
  $timestamp =strtotime ($date);
  $mdays =date (' t ', $timestamp);
  $ret [' Sdate ']=date (' y-m-1 00:00:00 ', $timestamp); $ret [' Edate ']=date (' y-m-'. $mdays.
  23:59:59 ', $timestamp);
  return $ret;
  //author:zhxia the application function GetFilter ($n) {$ret =array () of the above two functions;
  Switch ($n) {case 1://yesterday $ret [' Sdate ']=date (' y-m-d 00:00:00 ', Strtotime ('-1 day '));
  $ret [' Edate ']=date (' y-m-d 23:59:59 ', Strtotime ('-1 day '));
  Break
  Case 2://this week $ret =getweekrange (' y-m-d ');
  Break
  Case 3://One weeks $strDate =date (' y-m-d ', Strtotime ('-1 week '));
  $ret =getweekrange ($strDate);
  Break
  Case 4://The week before $strDate =date (' y-m-d ', Strtotime ('-2 week ')); $ret =gEtweekrange ($strDate);
  Break
  Case 5://$ret =getmonthrange (Date (' y-m-d ') this month);
  Break
  Case 6://last month $strDate =date (' y-m-d ', Strtotime ('-1 month '));
  $ret =getmonthrange ($strDate);
  Break
  return $ret; }

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.