查mysql中文参考手册
7.4.11 日期和时间函数

解决方案 »

  1.   

    function showdate($overnum,$varname,$postvar){
               echo "<select name='".$varname."'>";
               for($w=1;$w<=$overnum;$w++){
                   if(strlen($w)==1){
                      $z="0".$w;
                   }else{
                         $z=$w;
                    }
                   echo "<option value='".$z."'";
                   $z=intval($z);
                   if(intval($postvar)==$z){
                      echo " selected";
                   }
                   echo ">".$w."</option>";
               }
               echo "</select>";
      }  //列出今后三天的记录
      if(empty($_POST['showorder'])){
         $starttime=date("Y-m-d H:i:s");
         list($expyear,$expmonth,$expday)=explode("-",date("Y-m-d"));
         list($exphour,$expminute,$expsec)=explode(":",date("H:i:s"));
         $tmptime=mktime($exphour,$expminute,$expsec,$expmonth,$expday,$expyear);
         $tmptime=strtotime("+3days",$tmptime);
         $anontime=date("Y-m-d H:i:s",$tmptime);
         list($expyear1,$expmonth1,$expday1)=explode("-",$anontime);
      }  if(isset($_POST['showorder'])){
         $starttime=date("Y")."-".$_POST['frommonth']."-".$_POST['fromday']." ".$_POST['fromhour'].":00:00";
         $anontime=date("Y")."-".$_POST['tomonth']."-".$_POST['today']." ".$_POST['tohour'].":00:00";
         if($starttime>$anontime){
            $anontime=(date("Y")+1)."-".$_POST['tomonth']."-".$_POST['today']." ".$_POST['tohour'].":00:00";
         }
      }  $sql="select * from tablename where 时间字段>'".$starttime."' and 时间字段<'".$anontime."' order by 时间字段";
      $result=mysql_query($sql);  echo "<table border=0 cellpadding=2 cellspacing=1 width=100%>";
      echo "<form method=post action='".$_SERVER['PHP_SELF']."'>";
      echo "<tr bgcolor=ceafce align=middle><td colspan=5>";
      echo "从";
      if(isset($_POST['showorder'])){
         showdate(12,"frommonth",$_POST['frommonth']);
      }else{
            showdate(12,"frommonth",$expmonth);
       }
      echo "月";
      if(isset($_POST['showorder'])){
         showdate(31,"fromday",$_POST['fromday']);
      }else{
            showdate(31,"fromday",$expday);
       }
      echo "日";
      if(isset($_POST['showorder'])){
         showdate(23,"fromhour",$_POST['fromhour']);
      }else{
            showdate(23,"fromhour",$exphour);
       }
      echo "时 &nbsp;&nbsp;至";
      if(isset($_POST['showorder'])){
         showdate(12,"tomonth",$_POST['tomonth']);
      }else{
            showdate(12,"tomonth",$expmonth1);
       }
      echo "月";
      if(isset($_POST['showorder'])){
         showdate(31,"today",$_POST['today']);
      }else{
            showdate(31,"today",$expday1);
       }
      echo "日";
      if(isset($_POST['showorder'])){
         showdate(23,"tohour",$_POST['tohour']);
      }else{
            showdate(23,"tohour",$exphour);
       }
      echo "时";
      echo "&nbsp;&nbsp;<input type=submit name='showorder' value='显示'>";
      echo "</td></tr>";
      echo "</form>";
      echo "</table>";
      

  2.   

    <?php
    echo strtotime ("now"), "\n";
    echo strtotime ("10 September 2000"), "\n";
    echo strtotime ("+1 day"), "\n";
    echo strtotime ("+1 week"), "\n";
    echo strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
    echo strtotime ("next Thursday"), "\n";
    echo strtotime ("last Monday"), "\n";
    ?>