PHP计算指定日期所在周的开始和结束日期的方法

时间:2022-04-10 08:12:57

本文实例讲述了PHP计算指定日期所在周的开始和结束日期的方法。分享给大家供大家参考。具体实现方法如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<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].'-'.$_POST[month].'-'.$_POST[day].' 00:00:00';
echo('你输入的时间是:'.$time.'</br>');
$lastday=date("Y-m-d",strtotime("$time Sunday"));
echo('输入的时间星期第一天是:'.date("Y-m-d",strtotime("$lastday - 6 days")).'<br/>');
echo('输入的时间星期最后一天是:'.$lastday);
?>
</body>
</html>

希望本文所述对大家的php程序设计有所帮助。