✅ | Date-Cal.php
Here's a page to calculate the number of days between two dates, or the number of weeks and days between two dates.
<!DOCTYPE html>
<html>
<head>
<title>Date Cal</title>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=0.8">
<style>
@media (max-width: 980px) {
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #007eca;
}
}
@media (min-width: 981px) {
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #007eca;
background-image: url("https://dl.itslittlekevin.com/projects/5069.png");
background-repeat: no-repeat;
background-position: right center;
background-size: auto 100%;
}
}
h1, p, h4 {
text-shadow: 2px 2px 2px #00000055;
}
* {
color: white;
}
input[type="text"] {
color: black;
margin: 10px;
border-radius: 5px;
padding: 5px 15px
}
button {
font-size: 15px;
background-color: #00325565;
padding: 5px 15px;
border-radius: 5px;
border-width: 0px;
margin: 5px;
cursor: pointer;
}
h4 a {
text-decoration: none;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
text-align: center;
}
.spacer {
width: 75px;
display: inline-block;
}
.label-date {
text-shadow: 2px 2px 2px #00000055;
}
</style>
</head>
<body>
<div class="container">
<h1>日期计算器<br>Date Calculator</h1>
<form method="post">
<br><br>
<label for="date1" >起始日|Starts@:</label>
<input type="text" name="date1" id="date1" value="<?php echo isset($_POST['date1']) ? $_POST['date1'] : ''; ?>" placeholder="YYYY-MM-DD">
<br><br>
<label for="date2">结束日|Ends@:</label>
<input type="text" name="date2" id="date2" value="<?php echo isset($_POST['date2']) ? $_POST['date2'] : ''; ?>" placeholder="YYYY-MM-DD">
<?php
if (isset($_POST['calculate'])) {
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
if (!empty($date1) && !empty($date2)) {
$diff = abs(strtotime($date2) - strtotime($date1));
$days = floor($diff / (60*60*24));
$years = floor($days / 365);
$months = floor($days / 30);
$weeks = floor($days / 7);
$remainingDays = $days % 7;
echo "<p><br>相差 $days 天,或相差 $weeks 周 $remainingDays 天<br> Between them are $days Days, or $weeks Weeks and $remainingDays Days</p>";
echo "<p></p>";
} else {
echo "<p>请输入两个日期进行计算</p>";
}
}
if (isset($_POST['clear'])) {
unset($_POST['date1']);
unset($_POST['date2']);
}
?>
<br><br>
<button type="submit" name="calculate">计算 | Calculate</button><span class="spacer"></span><button type="submit" name="clear">清空 | Clear</button>
<h4><a href="https://itslittlekevin.com/gadgetslist">»返回工具列表 | Return to Gadgets List«</a></h4>
<p>© itsLittleKevin · All rights reserved.</p>
</form>
</div>
</body>
</html>