Results 1 to 3 of 3

Thread: [RESOLVED] SQL Dates

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    22

    Resolved [RESOLVED] SQL Dates

    Hi,

    I want to use a recordset to bring up all records which has a certain field with a date which is less than 5 days in advance. This includes dates in the past as well. Can anyone tell me how to do this using the .source property please?

    If this is not possible I guess it won't be too hard to use VB functions to do it? i.e. If rsName.Fields("date field") <= Date+5 Then ...?

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: SQL Dates

    you should query the recordset when you open it, something like:
    Code:
    rs.Open "SELECT * FROM Table1 WHERE dDate <= #" & Format$(Date + 5, "mm/dd/yyyy") & "#", conn

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: [RESOLVED] SQL Dates

    Try something like this (not tested):
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim strSQL As String
        Dim rs As New Recordset
    
        strSQL = "SELECT DATE "
        strSQL = strSQL & "FROM DATES "
        strSQL = strSQL & "WHERE DATE<=TO_DATE('" & DateAdd("D", 5, Date) & "','DD.MM.YYYY')"
    
        rs.Open strSQL, yourActiveConnection
    
        If Not rs.EOF Then
            Do Until rs.EOF
                Debug.Print rs.Fields("DATE")
    
                rs.MoveNext
            Loop
        End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width