Home >Database >Mysql Tutorial >机房收费系统之—怎样查询两个日期之间的数据

机房收费系统之—怎样查询两个日期之间的数据

WBOY
WBOYOriginal
2016-06-07 15:59:411166browse

日历控件刚刚学会怎么弄,但是要查询这两个语句之间的数据的语法我可是较劲脑汁啊,在网上查,自己试,可是每次不是语法错误就是连接不上数据库,我感觉这个方法就在我的眼前,我就是弄不出来,煞费苦心

日历控件刚刚学会怎么弄,但是要查询这两个语句之间的数据的语法我可是较劲脑汁啊,在网上查,自己试,可是每次不是语法错误就是连接不上数据库,我感觉这个方法就在我的眼前,我就是弄不出来,煞费苦心啊。下面是查询两个日历控件之间的代码,大家可以看看。

<span style="font-size:18px;">Private Sub Command1_Click()
    date1 = DTPicker1.Value&lsquo;这是日历控件
    date2 = DTPicker2.Value
    &#39;比较两个日期的大小
    If DateDiff("n", CDate(date1), CDate(date2)) < 0 Then
        MsgBox "起始日期与结束日期有冲突,请重新选择日期", , "提示"
        Exit Sub
    End If
    txtSQL = "select * from Recharge_Info where date >=&#39;" & date1 & "&#39; and date <=&#39;" & date2 & "&#39;"
    Set mrc = ExecuteSQL(txtSQL, Msgtext)
    If mrc.EOF = True Then
        MsgBox "没有信息"
        Exit Sub
    End If
    With MSFlexGrid1
   
        Do While mrc.EOF = False
            .CellAlignment = 4
            .Rows = .Rows + 1
            .TextMatrix(.Rows - 2, 0) = mrc!cardno
            .TextMatrix(.Rows - 2, 1) = mrc!addmoney
            .TextMatrix(.Rows - 2, 2) = mrc!Date
            .TextMatrix(.Rows - 2, 3) = mrc!Time
            .TextMatrix(.Rows - 2, 4) = mrc!userID
            .TextMatrix(.Rows - 2, 5) = mrc!Status
            mrc.MoveNext
            If mrc.EOF = True Then
                .Rows = .Rows - 1
            End If
        Loop
    End With
    mrc.Close
End sub

</span>
写了一大堆,其实最有用的是这句话
txtSQL = "select * from Recharge_Info where date >='" & date1 & "' and date 此方法不仅可以比较日期,以此类推,基本上带数字的都能比较吧!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn