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

青灯夜游
Release: 2023-04-10 20:04:01
Original
4203 people have browsed it

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("七","一","二","三","四","五","六")
Copy after login

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>";
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template