我想比较我的表单上的最后日期和当前日期,但它只比较日期和月份而不是年份。我可以做些什么来比较具有不同年份的日期?
1.db.inc.php
<?php
define('DB_NAME','ftender');
define('DB_USER','root');
define('DB_PASS','');
define('DB_HOST','localhost');
?>
2.fun.inc.php
<?php
include_once'db.inc.php';
function connect()
{
$con = mysqli_connect('localhost','root','','ftender');
if($con!=true)
{
echo 'Connection failed';
}
else
{
mysqli_select_db($con,'ftender');
}
}
function close()
{
$con = mysqli_connect('localhost','root','','ftender');
if($con!=true)
{
echo 'Connection failed';
}
else
{
mysqli_select_db($con,'ftender');
}
mysqli_close($con);
}
function clos (){
mysql_close();
}
function query(){
$con = mysqli_connect('localhost','root','','ftender');
if($con!=true)
{
echo 'Connection failed';
}
else
{
mysqli_select_db($con,'ftender');
}
$date=date("m/d/Y");
$q="SELECT * FROM adtender where lastdate>='$date' group by tendername";
$myData=mysqli_query($con,$q);
while($record=mysqli_fetch_array($myData,MYSQLI_ASSOC)){
echo '<option value="' . $record['tendername'] . '">' . $record['tendername'] . '</option>';
}
}
function fill(){
$myID=mysql_query("SELECT * FROM adtender");
while($r=mysql_fetch_array($myID)){
echo '<option value="' .$r['tenderid'] .'">' . $r['tenderid'] . '</option>';
}
}
?>
3.company.php
<!DOCTYPE HTML>
<?php
include_once 'fun.inc.php';
connect();
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type"content="text/html;charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"
type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<link href="style1.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen and (max-width: 360px)" href="portrait.css">
<link rel="stylesheet" type="text/css" media="screen and (min-width: 361px) and (max-width: 480px)" href="landscape.css">
<link rel="stylesheet" type="text/css" media="screen and (min-width: 481px)" href="desktop.css">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"
rel="Stylesheet"type="text/css"/>
<script>
function myFunction(){
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML= x;
var formInput = document.getElementById("theInput").value;
document.getElementById("newText").innerHTML= formInput;
var formFee = document.getElementById("theFee").value;
document.getElementById("newFee").innerHTML= formFee;
}
</script>
</head>
<body>
<div id="container">
<div id="banner">
</div>
<div id="navbar">
<ul>
<li align="center"><a href="welcome.php">मुख पृष्ठ</br> </a></li>
<li align="center"><a href="adtender.php">निविदा जोड़े</br> </a></li>
<li align="center"><a href="company.php">निविदा के लिए आवेदन करें </a></li>
<li align="center"><a href="subtenderprice.php">निविदा मूल्य दर्ज करें </a></li>
<li align="center"><a href="adqp.php">कोटेशन मूल्य दर्ज करें </a></li>
<li align="center"><a href="t1.php">उत्पन्न कार्य आदेश </a></li>
<li align="center"><a href="viewtender.php">सभी निविदा</br> </a></li>
<li align="center"><a href="vieworder.php">सभी कार्य आदेश </a></li>
<li align="center"><a href="../ftender.php">लोग आउट</br> </a></li>
</ul>
</div>
<div class="clear"></div>
<div id="content">
<br/><br/><br/><br/><br/>
<h2 align="center">निविदा के लिए आवेदन करें </h2>
<form action="comreg.php" method="post" onsubmit="return myFunction()">
<table width="400" align="center" border="0" style="border-color:#FFF;" cellpadding="4" cellspacing="0">
<tr>
<td>निविदा का नाम</td>
<td>
<select style="width:150px;" name="tendername" id="mySelect" onchange='choice();'>
<?php query() ?>
</select>
<?php close() ?>
</td> </tr>
<tr><td>कंपनी का नाम</td>
<td>
<input style="width:150px;" type="text" name="companyname" id="theInput">
</td>
</tr><tr><td>कंपनी का पता</td>
<td>
<input style="width:150px;" type="text" name="companyaddr" id="theInput">
</td>
</tr>
<tr colspan="6">
<td colspan="6" align="center">
<!--<input type="button" onclick="myFunction();" value="view">-->
<input type="submit" value="submit" name="submit">
</td>
</tr>
</table>
</form><script>
$("#mySelect").change(function(){
var selectedValue = $(this).val();
$("#theFee").val($(this).find("option:selected").attr("value"))
});
</script>
<br/><br/><br/><br/><br/><br/>
</div>
<div id="bottom"></div>
<div class="clear"></div>
<div id="footer">
</div>
</div>
</body>
</html>
此编码正在比较2个日期而不考虑年份。
答案 0 :(得分:0)
您可以使用MySQL date()
和month()
函数。
例如:
...where day(lastdate) >= day('$date') and month(lastdate) >= month('$date')
如果您的日期是字符串格式,则可以使用substring()
函数。
例如:“12/12/2016”(年/月/日)
提取日期:substring('$date',0,2);
提取月份:substring('$month',3,2);
substring
参数为:(string, position, length)
。
要详细了解substring()
功能:http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substring