Link to home
Start Free TrialLog in
Avatar of Lawrence Salvucci
Lawrence SalvucciFlag for United States of America

asked on

Date Criteria in Access Query

I need to set a date criteria in my query but not sure how to set it up. I need it to be between the current date and the same date last year so it captures a rolling year date range. Any ideas on how I would set this up as the criteria?
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lawrence Salvucci

ASKER

Perfect! Thank you very much!
Avatar of wsh2
wsh2

Dim strSQL as String
strSQL = _
    "SELECT * " & _
    "  FROM [MyTable] " & _
    " WHERE [MyTable].[MyDate] >= #12/31/2014# " & _
    "   AND [MyTable].[MyDate] <= #04/22/2015# "

Open in new window


OR

Dim dte1st as Date: dte1st = #12/31/2014#
Dim dte2nd as Date: dte2nd = #04/22/2015#
Dim strSQL as String
strSQL = _
    "SELECT * " & _
    "  FROM [MyTable] " & _
    " WHERE [MyTable].[MyDate] >= #" & dte1st & "# " & _
    "   AND [MyTable].[MyDate] <=  #" & dte2nd & "# "

Open in new window