Results 1 to 8 of 8
  1. #1
    get2guy is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    2

    between two dates - one of the dates is today-1

    Hi,

    I need a query criteria which is between two dates.

    The first is fixed, example #01/07/2024# and the other is TODAY-1

    Today is the 27/8/2024 so I need the values to be between 01/07/2024 and 26/8/2024



    Thanks in advanced to any reply

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Use Date - 1 with Between
    If you are going to hardcode dates then they need to be in mm/dd/yyyy or yyyy-mm-dd format.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    In sql 01/07/2024 is interpreted as 7th Jan

    you need to format your date as mm/dd/yyyy or the sql standard of yyyy-mm-dd

    31/8/2024 is ok because there are not 31 months in a year

  4. #4
    Join Date
    Apr 2017
    Posts
    1,792
    Or avoid any possible date format issues, and use 'BETWEEN DateSerial(2024,7,1) AND Date()-1'

  5. #5
    get2guy is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    2
    Works! thanks!
    Quote Originally Posted by ArviLaanemets View Post
    Or avoid any possible date format issues, and use 'BETWEEN DateSerial(2024,7,1) AND Date()-1'

  6. #6
    abuislam is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2024
    Posts
    4
    To filter values between a fixed date and TODAY-1, use this SQL query:sqlCopy codeSELECT *FROM your_tableWHERE date_column BETWEEN '2024-07-01' AND DATEADD(day, -1, GETDATE());

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by abuislam View Post
    To filter values between a fixed date and TODAY-1, use this SQL query:sqlCopy codeSELECT *FROM your_tableWHERE date_column BETWEEN '2024-07-01' AND DATEADD(day, -1, GETDATE());
    I seriously doubt that will work?
    In fact I tested it to be sure and got data type mismatch, which I would have expected.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    That is T-SQL syntax, not access sql syntax

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

Similar Threads

  1. Replies: 7
    Last Post: 09-14-2024, 01:44 AM
  2. Replies: 21
    Last Post: 06-23-2020, 11:45 AM
  3. Replies: 2
    Last Post: 09-19-2017, 11:31 AM
  4. Replies: 8
    Last Post: 12-02-2013, 03:46 PM
  5. Query that shows dates near today
    By LukeJ Innov in forum Queries
    Replies: 2
    Last Post: 09-03-2013, 04:57 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