dtlhy0771 2014-11-25 21:49
浏览 84
已采纳

CURDATE()不适用于MSSQL我可以在替换中使用什么

I have a simple issue I am using PDO with MSSQL I had CURDATE() before but that didn't work because MSSQL does not support that. Only MySQL does and I added GETDATE() but that is not working also. How would I be able to get the current date. I want the information to show first name order by id and todays date only.

$stmt = $db->prepare("SELECT * FROM students WHERE name='Firstname' And Getdate() ORDER BY id DESC");
$stmt->execute()

updated sorry this is what I meant

 $stmt = $db->prepare("SELECT * FROM students WHERE name='BOB' And Getdate() ORDER BY id DESC");
    $stmt->execute()

The whole query page.

    <head>

    <title></title>
    </head>
    <body>
    <?php
    //connects to the database
    require_once("../../db_connect.php");

    //prepared statement with PDO to query the database
    $stmt = $db->prepare("SELECT * FROM requests WHERE name='Bob' AND Date = CAST(GETDATE() AS DATE) ORDER BY id DESC");
    $stmt->execute();

    ?>

    <?php //start of the while loop ?>
    <?php while( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) { ?>

 <table border="1">

    <br>
    <tr> 
        <th style="width:25px; height: 25px;">ID</th>
        <th style="width:90px; height: 25px;">Name</th>
        <th style="width:40px; height: 25px;">Date</th>

    </tr>
    <tr style="width:25px">
    <?php $id = $row['id'];?>
    <?php echo  "<td> <a href='../../update.php?id=$id'>$id</a></td>"?>
        <td style="width:90px; height: 12px;"><?php echo $row['name']; ?></td>
        <td style="width:40px; height: 12px;"><?php echo $row['date']; ?></td>

    </tr>

    </table>

      <?php } //end of the while loop?>
    </body>

</html>

here is the page were user updates the information

<?php
    include('db_connect.php');
    $id=$_GET['id'];
    $result = $db->prepare("SELECT * FROM students WHERE id= :id");
    $result->bindParam(':id', $id);
    $result->execute();
    for($i=0; $row = $result->fetch(); $i++){
?>

<html>
<head>
<title></title>


</head>
<body class='body'>
<form action = "update_process.php"  method ="post" class="Form">

<p><input type ="hidden" name = "id" value="<?php print($id); ?>"</p>

<table border='1' align="center">
<tr>    
    <td>Name:</td>
<td><input type="text" value ="<?php  print($row['name']) ?>"name="name"></td>
</tr>

<tr>    
    <td>Date</td>
<td style="width: 303px">
<input type="text" value ="<?php echo date("Y-m-d",time())?>"name="date" style="width: 148px"></td>


</tr>

</table>

<input type="submit" value= "Update Information">
<br>
</div>
</form>


</body>
</html>
<?php
    }
?>
  • 写回答

1条回答 默认 最新

  • dpjuppr1361 2014-11-25 21:59
    关注

    There is no equivalent function in SQL Server to match CURDATE() from MySQL but you can mimic it by casting GETDATE() to DATE date type (which stripes the time component):

    CAST(GETDATE() AS DATE)
    

    However, your SQL statement still doesn't make sense, I suspect you mean to compare the date to a column in your table, something like this:

    SELECT * 
    FROM students 
    WHERE name='Firstname' 
    AND SomeDateColumn = CAST(GETDATE() AS DATE)
    ORDER BY id DESC
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端