- Joined
- May 20, 2004
- Messages
- 10,487 (1.37/day)
For the past 2 hours I've been getting annoyed with a simple sounding problem, however I seem stupid enough not to be able to solve it.
I have a table with some employees, all kind of irrelevant data, I just need the name and birthday. I want only employees who's birthday are within 2 weeks.
So my first thought would be select firstname, lastname, dateofbirth from employees where birthday is between date() and date()+day(14);
(the actual table uses different names, but since I don't want to confuse anyone with Dutch gibberish and other pointless issues)
Obviously the first idea doesn't work because date() returns 2007 and someones date of birth isn't 2007, it's some other random year. So I decided to create my own date using Day(dateofbirth) & "-" & Month(dateofbirth) & "-" & Year(Date()) (tried swapping mm/dd/yyyy around, using dashes, slashes, dots, nothing etc)
When I use this in combination with a single where clause it works fine, it returns the person whoms birthday is on the given date. However once I use between date() and date()+day(14) it gives me over half the employees and there seems to be no structure in the results. Just random dates. Even when I manually say between 06-02-2007 and 06-03-2007 it does not work. Not does < 06-02-2007, nor when using "06-02-2007" or #06-02-2007# etc)
So the second idea was to use convert(), make sure the new date is actually in date format, however ms access doesn't seem to know convert().
I've been messing around with this query and searching Google for a long time now, seeing how long it takes me I'm sure it's something extremely simple. Otherwise I would have found it/figured it out. But what?
I have a table with some employees, all kind of irrelevant data, I just need the name and birthday. I want only employees who's birthday are within 2 weeks.
So my first thought would be select firstname, lastname, dateofbirth from employees where birthday is between date() and date()+day(14);
(the actual table uses different names, but since I don't want to confuse anyone with Dutch gibberish and other pointless issues)
Obviously the first idea doesn't work because date() returns 2007 and someones date of birth isn't 2007, it's some other random year. So I decided to create my own date using Day(dateofbirth) & "-" & Month(dateofbirth) & "-" & Year(Date()) (tried swapping mm/dd/yyyy around, using dashes, slashes, dots, nothing etc)
When I use this in combination with a single where clause it works fine, it returns the person whoms birthday is on the given date. However once I use between date() and date()+day(14) it gives me over half the employees and there seems to be no structure in the results. Just random dates. Even when I manually say between 06-02-2007 and 06-03-2007 it does not work. Not does < 06-02-2007, nor when using "06-02-2007" or #06-02-2007# etc)
So the second idea was to use convert(), make sure the new date is actually in date format, however ms access doesn't seem to know convert().
I've been messing around with this query and searching Google for a long time now, seeing how long it takes me I'm sure it's something extremely simple. Otherwise I would have found it/figured it out. But what?