Results 1 to 2 of 2
  1. #1
    Dannasoft is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2012
    Posts
    1

    datepart in sql string

    Hi!



    I'm trying to create an sql string that will return all records from a table where the hour in a datetime field is between 7PM and 7AM.

    Here's the where clause I thought would work.

    Between DatePart("h",#11:59:00 PM#) And DatePart("h",#7:00:00 AM#) Or Between DatePart("h",#7:00:00 PM#) And DatePart("h",#11:59:00 PM#)

    Yet no records are returned. Any ideas?

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    rather than 'between' try using math compares: >=

    am trusting that you've researched DatePart syntax in VBA help and that is correct......

    also with any code - temporarily strip it down to 1 compare only and check results before adding more AND / OR

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Vba string
    By rchtan in forum Programming
    Replies: 5
    Last Post: 05-17-2012, 04:29 AM
  2. SQL + VBA String
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 08-22-2011, 08:44 AM
  3. Replies: 5
    Last Post: 07-18-2011, 06:07 PM
  4. Repeating dates, DateAdd/DatePart
    By Lauren1989 in forum Queries
    Replies: 5
    Last Post: 04-14-2011, 03:28 PM
  5. iff(datepart..
    By pranvera in forum Access
    Replies: 4
    Last Post: 11-19-2010, 11:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums