Please tell me how in MS ACCESS using sql query to create a query for the selection of dates relative to today's date? For example, there is a table of contacts. It has the datebirth attribute. And we need to make a request that will display the fields in which the birthday will be in the next two days, relative to today's date. (in general, like this thing in contact)
- How do you keep dates in the database? What type? Give a fragment from the designer of the table with dates, and also a desirable piece of data. - Ella Svetlaya
- I repeat once again, no one can help you until you show in what form you keep the dates in the database? Although the file itself lay out. - Ella Svetlaya
|
3 answers
SELECT * FROM [Контакты] WHERE [дата_рождения] IS NOT NULL AND DATEADD("yyyy", DATEDIFF("yyyy", [дата_рождения], DATE()), [дата_рождения]) BETWEEN DATE() AND DATEADD("d", 2, DATE())
- "The inconsistency of data types in the expression of the selection conditions" - miltan13
- While there is only a suspicion that [birthdate] is of a type other than date. Check it is not yet possible ... - kodv
- The answer has already been found, but with the type there everything is correct. - miltan13
- oneChecked in ACCESS. The construction of "DATEADD (" yyyy ", DATEDIFF (" yyyy ", [birth date], DATE ()), [birth date]) BETWEEN DATE () AND DATEADD (" d ", 2, DATE ())" does not generate errors. - kodv
- And you can throw your DB as an example. I can not understand why swears on data type. - miltan13
|
SELECT my_date FROM MyTable WHERE my_date >= #2016-03-30 00:00:00# AND my_date < #2016-04-02 00:00:00#;
From here took
- Doesn't print anything at all ( - miltan13
|
Thank you all, but this code helped me: SELECT Date FROM contact_face WHERE Date Birth Between DATE () And DATEADD ("d", 2, DATE ());
- It was the first option that I wrote to you, forgetting to think. But he should not work correctly, because at the moment now he will choose only those who were born from 03/31/2016 to 2.04.2016 (that is, no one). If a person was born, for example, 04/01/1990, then, in accordance with your condition, he will not get into the sample. Therefore, a construction appeared in my answer, which converts the date from 04/01/1990 to 04/01/2016. Although, if your request somehow magically still works correctly, then I congratulate you on this. - kodv
- For sure. You're right. Did not take into account - miltan13
|