0

This works...

select * 
from events 
where user_id = 47 
  and event_date Between #03/01/2015# And #03/31/2015#

But I get a syntax error when the month Is February or any other EVEN number.

select * 
from events 
where user_id = 47 
  and event_date Between #02/01/2015# And #02/31/2015#

Error:

Syntax error in date in query expression 'user_id = 57 and event_date Between #02/01/2015# And #02/31/2015#

Can't for the life of me figure out why ??

I'm using an Access database and has been working fine for 3 years up until today, possibly saved in a later version of Access to the original.

5
  • 5
    February has 28 days, so you use a date inexistent Commented Dec 2, 2014 at 9:40
  • 1
    #03/01/2015# is an invalid constant for a date in (standard) SQL. Which DBMS are you using? Commented Dec 2, 2014 at 9:41
  • 2
    @a_horse_with_no_name Looks like MS Access to me. Commented Dec 2, 2014 at 9:42
  • WHAT database??? This is not the same across all those databases that use SQL as their query language - which database are you talking about?? Commented Dec 2, 2014 at 9:44
  • As good practice I always use cast or convert functions to be sure that the syntax is correct. But still February doesn't have 31 days Commented Dec 2, 2014 at 9:45

2 Answers 2

3

February doesn't have 31 days.

Sign up to request clarification or add additional context in comments.

Comments

2

Don't you know feb has 28 days: Use

select * from events 
where user_id = 47 and event_date 
Between #02/01/2015# And #02/28/2015#

Even if you tried at least 29 (You may thought Leap day), It is acceptable. But how comes 31.

2 Comments

Yes of course ! Was driving me insane ! Its been working for years but just suddenly stopped, possibly after saving in a different version of access.
No, problem. From now, use 28 days for feb. 29 days for leap day.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.