C
C#•2w ago
Joch

SQL Query Filter by date range

Hello guys i hope you can help me in my problem. i have this data DateFrom DateTo ---------- ---------- 2018-01-01 2018-01-01 2018-01-02 2018-01-02 2018-01-04 2018-01-04 2018-01-07 2018-01-07 2018-01-10 2018-01-10 2018-01-14 2018-01-14 2018-01-17 2018-01-17 2018-01-18 2018-01-18 2018-01-20 2018-01-20 2018-01-23 2018-01-23 2018-01-26 2018-01-26 2018-01-30 2018-01-30 2018-02-01 2028-12-31 the data i want to check if exists is date from 2025-01-01 to 2025-01-31 i made this query it works fine (CONVERT(date, DateFrom) <= @DateTo AND CONVERT(date, DateTo) >= @DateFrom) but when i have this data DateFrom DateTo ---------- ---------- 2024-12-10 2024-12-10 2024-12-11 2024-12-11 2024-12-12 2024-12-12 2024-12-14 2028-12-31 the data 2024-12-14 2028-12-31 was showing in the query. thanks
7 Replies
cathei
cathei•2w ago
Is there a reason that it should not be showing? 2025-01-01 is included in that range Is year 2028 intended?
Joch
JochOP•2w ago
sorry my mistake.. i editted the 2nd data that till 2024-12-31 the last data in the first data it was in another table, 2018-02-01 2028-12-31, the data should show this when filter is 2025-01-01 to 2025-01-31, because it is in the range til 2028. but the 2nd data is from another table and might possible to same as first data. and last date is 2024-12-31 it should not show the data when filter.
cathei
cathei•2w ago
Right, so did you put wrong data in second table? :catthinking:
Joch
JochOP•2w ago
yes.. im very sorry about this.. it was my mistake i didnt see the data clearly. i though the 2nd data is till 2024 it was till 2028
cathei
cathei•2w ago
No need to sorry, problem solved? :catlaugh:
Joch
JochOP•2w ago
yes.. problem solve.. it seem i just too tired.. 😦 im very sorry.
cathei
cathei•2w ago
It happens. Get some sleep!

Did you find this page helpful?