我创建了一个表单如下。在EDOC字段中,当用户指定2天时,它应该添加到当前日期,它应该存储在phpmyadmin中。
这是我的代码。 我希望以m / d / y格式添加此日期。在phpmyadmin中,我将浏览器转换更改为Text / Plain:Dateformat和transformation选项为0,'%b-%d-%Y',' local'。
它正在添加并且它在弹出框中显示但是,在db中它存储了一些垃圾日期。所以在插入db之前我应该将其转换为另一种日期格式如何?
请回答这个问题。
谢谢。
Home.php
<form action="Confirm.php" method="post" enctype="multipart/form-data" novalidate>
Expected Date : <input name="edoc" type="text" id="edoc" size="15" maxlength="40" value=""/>
<button id='send' type='submit'>Add</button>
</form>
Confirm.php
<form action="Add.php" method="post" enctype="multipart/form-data" novalidate>
Expected Date :
<?php include_once('dbconn.php'); ?>
<input name="edoc" type="text" id="edoc" size="15" readonly="readonly" maxlength="40" value="<?php echo $_POST['edoc']; ?>"/>
<button id='send' type='submit'>Confirm</button>
</form>
dbconn.php
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("eservice",$dbhandle)
or die("Could not select database");
?>
Add.php
<?php
include_once('dbconn.php');
session_start();
$_SESSION['example']='Session Created';
$edoc = $_POST['edoc'];
$current = date('m/d/y');
$date = strtotime("+".$edoc." days", strtotime($current));
$ecd = date("m/d/Y", $date);
if($edoc !='')
{
$insQry = "Insert into 'main'(edoc) Values('$ecd');
$insertQ = mysql_query($insQry);
} ?>
<script language="javascript">
alert("Task created successfully" + "\n" + " <?php echo $ecd; ?>");
top.location.href = "Form.php"; //the page to redirect
</script>
答案 0 :(得分:0)
答案在这里:http://www.w3schools.com/sql/func_date_add.asp
SELECT OrderId,DATE_ADD(OrderDate,INTERVAL 45 DAY)AS OrderPayDate 来自订单
它也适用于其他类型的时间间隔,例如。秒,小时和年。
答案 1 :(得分:0)
只需在这个简单的行中写下你的两个变量$ date和$ edc
$date = date('m/d/y',strtotime('+2 days')); //Whatever days you want, it can be dynamic also
答案 2 :(得分:0)
我刚改变了格式,即
之前 - $ ecd = date(“ m / d / Y ”,$ date); 之后 - $ ecd = date(“ Y / d / m ”,$ date);
效果很好。
感谢。
$edoc = $_POST['edoc'];
$current = date('m/d/Y');
$date = strtotime("+".$edoc." days", strtotime($current));
$ecd = date("Y/m/d", $date);
$reviewed = $_POST['reviewed'];
$path = $_POST['path'];