Home >Backend Development >PHP Tutorial >How to get the day of the week for a specified date in php

How to get the day of the week for a specified date in php

青灯夜游
青灯夜游Original
2021-11-30 12:09:254204browse

Getting method: 1. Define the "array("7","1","2","3","4","5","6")" array; 2. Use " date("w",strtotime("specified date"))" converts the date into a number representing the week; 3. Use the number as a subscript and retrieve the corresponding day value from the array.

How to get the day of the week for a specified date in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php Get the day of the week that the specified date is

Determine the day of the week that the specified date is, that is, determine the day of the week that the specified date is.

We can use date("w",strtotime("specified date")) to achieve this; but the return value of this statement is: a number representing the day of the week (0 represents Sunday[ Sunday], 6 means Saturday [Saturday]).

We can create an array as follows:

array("七","一","二","三","四","五","六")

Use the return value of the above date() statement as a subscript, and then take out the corresponding day of the week value in the array.

Let’s take a look at the implementation code:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$weekarray=array("7","1","2","3","4","5","6");
echo "一周的第 ".$weekarray[date("w",strtotime("2021-11-29"))]." 天<br>";
echo "一周的第 ".$weekarray[date("w",strtotime("2021-11-30"))]." 天<br>";
echo "一周的第 ".$weekarray[date("w",strtotime("2021-12-1"))]." 天<br>";
?>

How to get the day of the week for a specified date in php

How to get the day of the week for a specified date in php

## Recommended learning: "

PHP Video Tutorial

The above is the detailed content of How to get the day of the week for a specified date in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn