【发布时间】:2014-01-13 13:15:18
【问题描述】:
我有一个带有两个输入的 html 表单
<input type="datetime" name="start" id="start" ></input>
<input type="datetime" name="stop" id="stop" ></input>
还有一个send.php 将表单内容邮寄给我。
在 send.php 中,我想计算 STOP 和 START 之间的天数差异,如差异 = STOP - START。如果时间差是正数并且大于 1 HOUR,那么我想多加一天。
If START = 02/01/2014 14:58:21
If STOP = 07/01/2014 14:59:21
那么输出 = 5 天
If START = 02/01/2014 14:58:21
If STOP = 07/01/2014 14:59:21
然后输出 = 6 天
我怎样才能做到这一点?
send.php 应该通过邮件发送结果。
所以在我的.html 我有类似的东西
<form action="send.php" method="get">
<div id="datetimepicker" class="input-append date">
<input type="datetime" name="START" id="START" ></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
<div id="datetimepicker" class="input-append date">
<input type="datetime" name="STOP" id="STOP" ></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</form>
我的send.php 是
<?php
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$START= $_GET['START'];
@$STOP= $_GET['STOP'];
@$email= addslashes($_GET['email']);
$_start = new DateTime($_POST['start']); // or new DateTime($_POST['start']);
$_stop = new DateTime($_POST['stop']);// or new DateTime($_POST['stop']);
$interval = $_start->diff($_stop);
$to = "me@me.com";
$subject = "Calculator";
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "Return-Path: $email\r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$message = "<html><body style=\"font-family:Calibri; font-size:14.5px;\">";
$message .= " result between $STOP and $START is ....days
ID: $pfw_ip <br/>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
?>
the error i get now is Catchable fatal error: Object of class DateInterval could not be converted to string in
【问题讨论】:
标签: php html get datepicker