Home  >  Article  >  Backend Development  >  How to calculate the start and end dates of a week in PHP

How to calculate the start and end dates of a week in PHP

墨辰丷
墨辰丷Original
2018-06-12 09:41:581909browse

This article mainly introduces the method of PHP to calculate the start and end date of the week in which the specified date is located. It involves the skills of operating date and time in PHP. It has certain reference value. Friends in need can refer to this article.

The example describes how PHP calculates the start and end dates of the week on a specified date. The specific implementation method is as follows:

<html>
<head>
<title>计算一周开始结束日期</title>
</head>
<body>
<form method="post" action="./index.html" enctype="utf-8">
<table>
 <tr><td>输入年份</td>
 <td><input name="year" type="text" maxlength="4" /></td>
 </tr>
 <tr><td>输入月份</td>
 <td><input name="month" type="text" maxlength="2" /></td>
 </tr>
 <tr><td>输入天</td>
 <td><input name="day" type="text" maxlength="2" /></td>
 </tr>
 <tr><td colspan="2"><input type="submit" value="计算" />
</td></tr>
</table>
</form>
<?php
$time= $_POST[year].&#39;-&#39;.$_POST[month].&#39;-&#39;.$_POST[day].&#39; 00:00:00&#39;;
echo(&#39;你输入的时间是:&#39;.$time.&#39;</br>&#39;);
$lastday=date("Y-m-d",strtotime("$time Sunday"));
echo(&#39;输入的时间星期第一天是:&#39;.date("Y-m-d",strtotime("$lastday - 6 days")).&#39;<br/>&#39;);
echo(&#39;输入的时间星期最后一天是:&#39;.$lastday);
?>
</body>
</html>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

How to implement gzip configuration and modification in php in apache environment

How to use php to call KyotoTycoon

How to upload files and images using php

The above is the detailed content of How to calculate the start and end dates of a week 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