I am using a where clause to extract data but into database I have datetime stamp and I want to extract data by using only date information.
select *
from invoice
where invoice_date = '2019-06-24'
But I have into database invoice_date = 2019-06-24 04:30:00.000
Cast it to date:
select *
from invoice
where CAST(invoice_date as DATE) = '2019-06-24'
I would personally use "proper" date logic:
SELECT {Column List}
FROM dbo.invoice i
WHERE i.invoice_date >= '2019-06-24'
AND i.invoice_date < '2019-06-25';
If you're using a parameter, then you would use DATEADD:
SELECT {Column List}
FROM dbo.invoice i
WHERE i.invoice_date >= @DateParam
AND i.invoice_date < DATEADD(DAY, 1, @DateParam);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With