I need to select data from SQL Server database between the 1st day of the current month and current day.
SELECT *
FROM table_name
WHERE date BETWEEN "1st day of current month" AND "current day"
I need to select data from SQL Server database between the 1st day of the current month and current day.
SELECT *
FROM table_name
WHERE date BETWEEN "1st day of current month" AND "current day"
5条答案
按热度按时间fdbelqdn1#
You can make use of
EOMONTH()
to jump to the last day of the month, of the previous month. Then, just add 1 day, by usingDATEADD()
with 1 as the increment for the day, to get the 1st day of the current month.7eumitmz2#
I think this should work,
h43kikqp3#
May this will help you,
z9smfwbn4#
I don't recommend using
between
for this purpose. I prefer to have code that works on bothdate
s anddatetime
s without modification.In addition, SQL Server has the convenient
datefromparts()
function. So, I recomend:dffbzjpn5#