1 2 3 4 5 6 7 8 |
CREATE TABLE #temp (sold_date DATE) INSERT INTO #temp VALUES ('20180115'),('20180130'),('20180131'),('20180201'),('20180228') SELECT * FROM #temp |
1 2 3 4 5 6 7 |
sold_date ---------- 2018-01-15 2018-01-30 2018-01-31 2018-02-01 2018-02-28 |
Suppose we only want the end of the day observation, we sure can hard code like this.
1 2 3 4 |
SELECT * FROM #temp WHERE MONTH(sold_date) = 01 AND DAY(sold_date) = 31 OR MONTH(sold_date) = 02 AND DAY(sold_date) = 28 |
1 2 3 4 |
sold_date ---------- 2018-01-31 2018-02-28 |
Or we can use EOMONTH() function.
1 2 3 |
SELECT * FROM #temp WHERE sold_date = EOMONTH(sold_date) |
1 2 3 4 |
sold_date ---------- 2018-01-31 2018-02-28 |