Its a lending an item table, I can show item which are forward from today's date. I need to display records including today's date and only upto 3pm today
SELECT *
FROM dbo.Lending
WHERE convert(DATE,'20/08/2022', 103) >= GETDATE();
CodePudding user response:
You may try:
SELECT *
FROM dbo.Lending
WHERE date_col
BETWEEN
DATEADD(d, 0, DATEDIFF(d, 0, GETDATE())) AND -- today at midnight
DATEADD(mi, 900, DATEDIFF(d, 0, GETDATE())) -- today at 3pm
Note that 3pm is 900 minutes past midnight, hence the above calculation.
CodePudding user response:
You can try using datetime instead of date:
SELECT * FROM dbo.Lending
WHERE column_name between
cast(cast(getdate() as date) as datetime)
and dateadd(hour,15,cast(cast(getdate() as date) as datetime))