在日期范围内显示数据库中的记录

时间:2015-10-02 08:28:21

标签: c#

我在数据库中有一些1天的活动,需要从午夜到午夜显示它们。所以例如今天的活动将过期而不会在今晚的午夜显示,明天的活动将显示在今晚午夜,或刚刚过夜。我正在使用' DateTime.Today'但是我没有得到我需要的结果。

3 个答案:

答案 0 :(得分:0)

使用

DateTime.Today;

而不是

DateTime.Today;

因为SELECT * FROM yourTable WHERE DateDiff(d,dateCouName, GetDate())=0 将返回日期+时间(12:00:00),这可能不会选择所有记录。所以最好只发送日期而不是时间。

答案 1 :(得分:0)

使用select sql语句仅获取今天的记录

void Foo()
{
 string str; //reference to string is created which points to null
 str = "foo";//string object is created and "str" is now points to it   

 Bar(out str);//pass "str" as a reference to reference
}

void Bar(out string str1) //"str1" is like a pseudomin for "str". If you change "str1" the "str" changes to.
{
 str1 = "bar";//new string object is created and both "str1" and "str" pointed to it
}

答案 2 :(得分:0)

如果您使用简单的SQL查询来执行此操作,它应如下所示:

INSERT INTO

其中CURRDATE()返回当前日期。例如,今天将是2015年10月2日。

如果您使用EF进行操作,可以使用LINQ,它看起来像这样:

<?php
$totalsum=0;

$sql = "SELECT  form_details_section_id,SUM(mark),COUNT(mark) FROM audit_section_markrecord WHERE audit_section_id = '$audit_no' GROUP BY form_details_section_id ";

$result = mysqli_query($db, $sql);

    while($row = mysqli_fetch_assoc($result)) { 

    $query1 = "SELECT * FROM form_details_section WHERE id = '$row[form_details_section_id]' ";
    $result1 = $db->query($query1);
    $row1 = $result1->fetch_array();

    $query6 = "SELECT COUNT(mark) FROM audit_section_markrecord WHERE `form_details_section_id` = '$row[form_details_section_id]' ";
    $result6 = $db->query($query6);
    $row6 = $result6->fetch_array();    

    $mark = $row['SUM(mark)'];
    $final_mark = $row1['final_mark'];
    $section_mark = $row6['COUNT(mark)'];
    $sub = ($section_mark*10);
    $subtotal = ($mark/$sub);
    $section_total = round($subtotal*$final_mark);
    echo"
    <tr class='odd gradeX'>
    <td>".$j."</td>
    <td>".$row1['category']."</td>
    <td>$section_total</td>
    ";
    $j++;

}
?>
</tr>
    <td colspan="2" align="right">Total Score:</td>
    <td><?php $totalsum ?></td>

我真的不知道db是如何构建的,所以我不能更具体