I'm trying to create a report that gets records from a SQL Server database where the delivery date is today.
I've tried
select * from (tablename)
where delivery_date = getdate()
Although that didn't give me any errors, it didn't give me any records either.
I'm assuming it is because all dates are like:
2016-03-15 00:00:00.000
Perhaps, I need to truncate the date to remove the time-stamp and then try?
You can try a query like below
Also if all delivery dates have time part like
00:00:00.000
for sure thenwould work as good.
Try this:
If delivery_date is always midnight (
00:00:00.000
), then compare it like this:Using
datediff
like this is a quick way to truncate the time part of a datetime value.I'd just create 2 params. One for
StartTime
and one forEndTime
and use those in my query.Yo need to remove the time part of the delivery_date field AND the GETDATE() value.