Hongmu Notes
Home Language Notes php The day of the month, php determines the day of the week today is this month
Language Notes PHP

php The day of the month, php determines the day of the week today is this month

php The day of the month, php determines the day of the week today is this month

There is a very powerful system function date() function in PHP. Clever use of it can display any time we need.

For example, today I encountered a need to determine which day of the month it is today. I will not discuss whether there are any problems and whether this kind of language is meaningful. Let's look at how to use PHP to implement this function.

This function mainly uses the w j parameters of the date() function. The date() function has many parameters.

PHP date() parameter description The explanation of the two parameters w j is as follows:

w represents the day of the week, and the number represents 0 (representing Sunday) to 6 (representing Saturday)

j The day of the month, the number represents from 1 to 31. The specific algorithm for using PHP to determine which day of the week today is this month is: using the relationship between the date (that is, the number) and the total number of days in the week (7 days), borrow the ceil() function to directly determine the day of the week today is this month.

The ceil() function is used to calculate the smallest integer greater than a specified number (float number).

For example: Suppose the 3rd of a certain month is a Thursday, then the value of ceil(3/7) will be 1, which indicates that this day is the first Thursday of the month. The calculation formula for the next Thursday is ceil(10/7), whose value is 2, indicating that the 10th is the second Thursday. Others can be deduced in turn. According to this algorithm, it can be determined that the calculation formula for calculating which day of the week today is in the month is set to: ceil (date/7).

Let’s look at a specific example:

/*

功能: 计算今日是当月的第几个星期几

*/

header('content-Type: text/html; charset=utf-8');

$wk_day=date('w'); //得到今天是星期几

$date_now=date('j'); //得到今天是几号

$wkday_ar=array('日','一','二','三','四','五','六'); //规范化周日的表达

$cal_result=ceil($date_now/7); //计算是第几个星期几

$str=date("Y年n月j日")." 星期".$wkday_ar[$wk_day]." - 本月的第 ".$cal_result." 个星期".$wkday_ar[$wk_day];

echo $str;

?>

The results of this run are as follows:

Tuesday, May 21, 2013 - the 3rd Tuesday of the month

This article was originally published on php Chinese website. Please indicate the source when reprinting. Thank you for your respect! ::(insidious)

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

Kakaka, one bug can be fixed in one day! <b>Fatal error</b>: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in

Kakaka, one bug can be fixed in one day! <b>Fatal error</b>: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in Summary of pitfalls

Regarding the problem of $stmt->execute($categoryIds); passing parameters. I'm really convinced. Just such a question has troubled me all afternoon! It wasn't until I went to look through the documents at night that I discovered that it was a problem with this thing. PDOException: SQLSTATE[HY093] error, the core reason is that the parameter placeholder in the SQL statement is different from the execu...
👁 75
Resource website typecho001 template

Resource website typecho001 template Program Notes Typecho

typecho001 template template please do not modify the folder name of this template. The folder name is: typecho001 1.4 Fix the js output problem on the article page 1.3 Fix the error prompt when the plug-in is not installed Optimize the list page code output 1.2 Fix the comment function and add a custom homepage title 1.1 Fix the comment reply asymmetry function Add a separate title setting function on the homepage Add the website favicon.ico icon Add one...
👁 198
Modification of typecho paging style

Modification of typecho paging style Program Notes Typecho

Sir, times have changed! Typecho is currently the most perfect solution, because Baidu can only see the code of fixed thinking. The actual generated HTML code is breathtakingly clean and fully customized, including adding classes to the li element, adding classes to the a element, adding classes to the previous page and next page, and removing the li tags that come with typecho to express more. I can even add some text to the content inside...
👁 517