Results 1 to 8 of 8

Thread: Filtering DateTime Column

  1. #1

    Thread Starter
    Hyperactive Member nazeem_khan's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    305

    Filtering DateTime Column

    How do i filter a recordset on DateTime Column for a given date(sql Server)?...

  2. #2
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Format it first to "mm/dd/yyyy" then filter.

  3. #3

    Thread Starter
    Hyperactive Member nazeem_khan's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    305
    Originally posted by andreys
    Format it first to "mm/dd/yyyy" then filter.
    well....

    I tried converting the DateTime Column to dd/mm/yyyy column but it didnt work. Anyway i will explain again. I already have a recordset, which have one or more datetime columns. I need to compare only the given date with the datetime column. Because it is datetime column, when i compare it is not giving the result properly. So i need to convert the datetime column to date column for filtering records based on a given date.

    I tried giving like this but it didnt work in filtering....
    Format([Membership Expiry Date],'dd/mm/yyyy') = 06/04/2003

  4. #4
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    VB Code:
    1. rst.Filter "[Membership Expiry Date] = " & "2004/04/06"
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  5. #5

    Thread Starter
    Hyperactive Member nazeem_khan's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    305
    Originally posted by swatty
    VB Code:
    1. rst.Filter "[Membership Expiry Date] = " & "2004/04/06"
    I mean the Filter Column is DateTime Column And Filter Value is Date Only. Database i'm using is SQL Server 2000...Can u plz give me solution for this....

  6. #6
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    When filtering on a datetime field with only a date you need to get the values between date 00:00:00 And date 23:59:59 +1

    VB Code:
    1. Dim d As Date
    2. Dim dd As Date
    3. d = Date
    4. dd = DateAdd("d", 1, d)
    5. rst.Filter "[Membership Expiry Date] Between #" & d & "# And #" & dd & "#"

    If you got a date value , add a day to it these are used like
    2003/04/06 00:00:00
    2003/04/07 00:00:00
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  7. #7

    Thread Starter
    Hyperactive Member nazeem_khan's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    305
    Originally posted by swatty
    When filtering on a datetime field with only a date you need to get the values between date 00:00:00 And date 23:59:59 +1

    VB Code:
    1. Dim d As Date
    2. Dim dd As Date
    3. d = Date
    4. dd = DateAdd("d", 1, d)
    5. rst.Filter "[Membership Expiry Date] Between #" & d & "# And #" & dd & "#"

    If you got a date value , add a day to it these are used like
    2003/04/06 00:00:00
    2003/04/07 00:00:00
    Let me try and let u know....thanx

  8. #8

    Thread Starter
    Hyperactive Member nazeem_khan's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    305
    Originally posted by nazeem_khan
    Let me try and let u know....thanx
    I tried ur code but instead of # if i give it in single quotes it works. But i have one more question?. How do i pick only the dates that not between 08/02/2003 12:00:00AM and 08/02/2003 11:59:59PM. Thanx for ur help in the previous post and i would really appreciate if u could help me in this...

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