Results 1 to 6 of 6

Thread: [RESOLVED] Searching an Access Date/Time field?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    carmi,IL.
    Posts
    105

    Resolved [RESOLVED] Searching an Access Date/Time field?

    Good Morning.
    I am having trouble searching an Access(2000) DataTime Field.

    The field holds both the Date and Time: But I only want to search this field by the Date.

    Below is my search string it returns no records. (Does not give an error, just no records.)

    searchsql = "select * from slog where wdate=" & Chr$(35) & FormatDateTime(DTPicker2.Value, vbShortDate) & Chr$(35)
    David M. Camp

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Searching an Access Date/Time field?

    Try searching a range:

    searchsql = "select * from slog where wdate >= #" & _
    DateSerial(Year(wdate), Month(wdate), Day(wdate)) & _
    "# And wdate < #" & _
    DateSerial(Year(wdate), Month(wdate), Day(wdate) + 1) & "#;"

    Note that DateSerial() handles rollover automagically, so you can simply add 1 to the day without worrying about if it's the last day of the month.

    DateSerial() is better for this than DateAdd() because DateAdd() would retain the time information, thus returning undesired results.

    Of interest is that the first term needs to be ">=" the date itself, instead of ">" the day before. That's because a date without a time component resolves to midnight at the beginning of that day.
    Last edited by Ellis Dee; Aug 11th, 2007 at 07:57 AM.

  3. #3
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Searching an Access Date/Time field?

    I m little bit confused, date serial returns , a date, but that is compared to a Date Time Field.
    So even ith Ellis Dee's suggestion , the result wont come right?

    try like

    Code:
    "select * from slog where left(wdate,10) =" & Chr$(35) & FormatDateTime(DTPicker2.Value, vbShortDate) & Chr$(35)
    in your sql.

    IIF(Post.Rate > 0 , , )

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    carmi,IL.
    Posts
    105

    Re: Searching an Access Date/Time field?

    Thank you zeezee, that was what I was looking for. Well Done!!!!
    David M. Camp

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Searching an Access Date/Time field?

    Quote Originally Posted by zeezee
    I m little bit confused, date serial returns , a date, but that is compared to a Date Time Field.
    So even ith Ellis Dee's suggestion , the result wont come right?
    All dates have a time component. DateSerial() returns a datetime value with a time component of 0, which is midnight.

  6. #6
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Searching an Access Date/Time field?

    Quote Originally Posted by Ellis Dee
    All dates have a time component. DateSerial() returns a datetime value with a time component of 0, which is midnight.
    Oh ,thanks Ellis, I didnt know about this.
    IIF(Post.Rate > 0 , , )

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