So I have this:
(CURDATE() BETWEEN start_date AND end_date)
Works fine.
But when the CURDATE()
is 2011-12-02 and the end_date
is 2011-12-02 will it grab the row?
E.g my start_date is 2011-12-01 00:00:00 and my end date is 2011-12-02 23:59:59
So it only works when the date is between but not if it's ON the end_date
itself.
Or maybe it should check for the time too, because it still needs to be selected with this query when it's 2011-12-02 15:30:00 for example.
How can I do this?
The SQL BETWEEN Operator The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.
Yes it includes start and end date and you could easily find this in the documentation.
declare @StartDate date = '20170401' , @EndDate date = '20170731'; ;with Months as ( select top (datediff(month, @startdate, @enddate) + 1) [Month] = dateadd(month, row_number() over (order by number) -1, @StartDate), MonthEnd = dateadd(day,-1,dateadd(month, row_number() over (order by number), @StartDate)) from master ...
Since both columns are timestamps, you need to make sure times don't trip you up. To keep the times from tripping you up, cast the timestamps to date.
where current_date between cast(start_date as date)
and cast(end_date as date);
Well, you could try
CURDATE() BETWEEN start_date AND DATE_ADD(end_date, INTERVAL 1 DAY)
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