@begindate='2002-3-4'
select * from table where FromDate>=@begindate and Todate<=dateadd(dd,@begindate,25)

解决方案 »

  1.   

    哥们,你误会了我的意思,我是想取出时间段,用的找sql嘛?
      

  2.   

    不好意思,可能是我太笨了吧,試下以下代碼
    '放在module中
    Type DateInternal
          frmDate As Date
          toDate As Date
    End Type
    '放在form中
    Private Sub Form_Load()
    Dim Frdate As Date
    Dim toDate As Date
    Dim theDay As Integer
    Dim MyDate() As DateInternal
    ReDim MyDate(0)
    Frdate = #12/4/2002#
    toDate = #5/16/2004#
    theDay = Day(Frdate)
    If theDay > 25 Then
        Exit Sub
    End If
    While Frdate < toDate
        MyDate(UBound(MyDate)).frmDate = Frdate
        If Day(Frdate) <= 25 Then
            MyDate(UBound(MyDate)).toDate = Frdate + (25 - Day(Frdate))
        Else
            MyDate(UBound(MyDate)).toDate = DateAdd("m", 1, Frdate + (25 - Day(Frdate)))
        End If
        If MyDate(UBound(MyDate)).toDate >= toDate Then
            MyDate(UBound(MyDate)).toDate = toDate
        End If
        Frdate = MyDate(UBound(MyDate)).toDate + 1
        ReDim Preserve MyDate(UBound(MyDate) + 1)
    Wend
    For i = 0 To UBound(MyDate) - 1
       Text1.Text = Text1.Text & MyDate(i).frmDate & " " & MyDate(i).toDate & vbCrLf
    Next
    End Sub