从数据库中提取时,日期格式不分开

时间:2012-11-02 12:08:28

标签: php javascript mysql

我有一个名为item_request的表,它有两个名为projectmanager和createddate的表,其时间戳格式为2012-09-11 17:46:25。

现在我想以另一种形式调用这两个字段来计算两个不同日期之间的用户条目。日期字段是从时间戳中获取的。使用此表单即可通过日期时间选择器发送值,格式为10-12 -2012但是数据库中的值是以不同的格式,并且im发送的值是不同的格式。如果plzzz可以帮助我们。

以下是我的表单的代码:

<?php 
include("config.php");
ob_start();
error_reporting(0);
if(!isset($_SESSION[username]))
header("location: index.php");
if(isset($_POST[submit]))
{
$projectmanager=mysql_real_escape_string($_POST['projectmanager']);
$date=mysql_real_escape_string($_POST['date']);
$dateexp = explode("-",$date);
$date = mysql_real_escape_string($dateexp[0]."/".$dateexp[1]."/".$dateexp[2]);


$date1=mysql_real_escape_string($_POST['date1']);
$dateexp1 = explode("-",$date1);
$date1 = mysql_real_escape_string($dateexp1[0]."/".$dateexp1[1]."/".$dateexp1[2]);

echo $queryuser= "select * from  item_request where projectmanager=$projectmanager AND (requireddate>=$date AND requireddate<=$date1)";

}
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Project Managers Registrarion</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script language="javascript" type="text/javascript" src="js/datetimepicker.js">

//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com

</script>

</head>
<body>

<div class="container">
  <div class="header"><a href="#"><img src="images/cherry-new.jpg" width="79" height="93" /></a> 
    <!-- end .header --></div>
<?php include("rightMenu.php");?>
  <div class="content">
    <h1>PR Count</h1>
    <div style="padding:10px 0px; text-align:center; color:#990000;">
    </div>
    <form action="" method="post" name="loginform">


<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
  <td>Project Managers</td>
           <td><select name="projectmanager" style="width:145px;" id="projectmanager" onChange="showUser(this.options[this.selectedIndex].id)">
               <option value="">Select</option>
               <?php $queryuser= "select * from  projectmanagers";
              $fetuser1user = mysql_query($queryuser);
              while($fetuser = mysql_fetch_array($fetuser1user)){
        ?>
               <option id="<?php echo $fetuser['id']?>" value="<?php echo $fetuser['id']?>"><?php echo $fetuser['projectmanager']?></option>
               <?php }
        ?>
             </select></td>
     </tr>
  <tr>
    <td>Date From</td>
    <td>
      <input id="date" type="text" size="20" name="date"  /><a href="javascript:NewCal('date','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
  </tr>
  <tr>
    <td>Date To</td>
    <td>
      <input id="date1" type="text" size="20" name="date1"><a href="javascript:NewCal('date1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
      <input type="submit" name="submit" id="submit" value="Submit" onClick="return formvalidate();"/>
 </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>


       <table width="100%" border="1"><tr>
                <td width="18%" valign="middle" class="tableheading">PI.No.</td>
                <td width="18%" valign="middle" class="tableheading">Project Manager</td>
                <td width="18%" valign="middle" class="tableheading">Date Created</td>
                <td width="15%" valign="middle" class="tableheading">Action</td>
                </tr>
                 <?php 
                 // to print the records
                $select = "select * from item_request";
                $query1 = mysql_query($select);  
                 while($value = mysql_fetch_array($query1)){ ?>

                <tr>
                <td class="tabletext"><?php echo $value[id];?></td>
                <td class="tabletext"><?php echo $value[projectmanager];?></td>
                <td class="tabletext"><?php echo $value[datefrom];?></td>               
                <td class="tabletext"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $value[id];?>&cmd=edit"><img src="images/edit.png" width="25" height="25" border="0" title="Edit" /></a>
               <a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php  echo $value[id];?>&cmd=delete" onclick="return confirm('Are you sure you want to delete <?php  echo $value[projectmanager];?>?')"><img src="images/deleteBtn.png" width="25" height="25" border="0" title="Edit" /></a></td>
              </tr><?php }?>
                </table>
    </form>


    <!-- end .content --></div>
  <?php include("footer.php");?>
  <!-- end .container --></div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

替换此函数调用...

javascript:NewCal('date','ddmmyyyy');

这一个......

javascript:NewCal('date','ddmmyyyy',true,24);

希望它有所帮助。