PHP has a very powerful system function date () function. The ingenious use of him can be achieved by showing any time we need. For example, today I have a need to judge today is the first few weeks of this month, here is not to discuss the question and whether it is meaningful, the following specific see how to use PHP to achieve this function.
This feature is mainly used in the date () function of the W J two parameters, date () function parameters are many, want to understand the function of the reference site article:
PHP date () parameter description
The explanations for W J two parameters are as follows:
W represents the day of the week, with a number representing 0 (Sunday) to 6 (means Saturday)
The day of the J month, the number means 1 to 31.
Using PHP to determine the number of days of the month today is the specific algorithm for the first few weeks:
Using the relationship of the date (that is, the day) and the total number of days of the week (7 days), use the Ceil () function to draw the first few weeks of this month. The Ceil () function computes the smallest integer that is greater than the specified number (float, float). Like what:
Assuming that the month of 3rd is Thursday, the value of Ceil (3/7) will be 1, indicating that the day is the first Thursday of the month. The next Thursday formula is Ceil (10/7) with a value of 2, indicating that 10th is the second Thursday. The other is the analogy. Based on this algorithm, it can be determined that the calculation formula for the first few weeks of the current month is set to: ceil (Date/7). Let's look at a specific example:
<?php
/* Function: Calculate today is the month of the first few weeks a few
/header (' content-type:text/html; Charset=utf-8 ');
$wk _day=date (' W '); Get today is the day of the week
$date _now=date (' j ');//Get Today is the date
$wkday _ar=array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ');//standardize the expression of Sunday
$ Cal_result=ceil ($date _NOW/7); The calculation is the first few weeks
$str =date ("Y-year N-month J-Day"). "Week". $wkday _ar[$wk _day]. "--this month's section, $cal _result." A week. $wkday _ar[$wk _day];
echo $str;
? >
The results of this operation are as follows:
May 21, 2013 Tuesday-3rd Tuesday of the Month