I want to check whether a date is between start date and end date.
i have added a where clause
where datepaid between '2010-04-01' AND '2010-04-15'
but the problem is that it excludes '2010-04-15'.
It should include end date also how can i do this?
Please help me on this
Regards,
pankaj
明确指定时间部分:
WHERE datepaid BETWEEN '2010-04-01 00:00:00' AND '2010-04-15 23:59:59'
Perhaps your dates include intraday times. Try this instead:
where '2010-04-01' <= datepaid AND datepaid < '2010-04-16'
WHERE datepaid >= '2010-04-01'
AND datepaid < '2010-04-15' + INTERVAL 1 DAY
尝试
where datepaid between '2010-04-01' AND '2010-04-15 23:59:59'
It's probably due to dates having time:
select
'2010-04-15' between '2010-04-01' AND '2010-04-15', -- 1
'2010-04-15 12:00:00' between '2010-04-01' AND '2010-04-15', -- 0
'2010-04-15 12:00:00' between '2010-04-01 00:00:00' AND '2010-04-15 23:59:59' -- 1
Either add time to range delimiters or truncate values before comparison:
select
'2010-04-15 12:00:00' between '2010-04-01 00:00:00' AND '2010-04-15 23:59:59' -- 1
cast('2010-04-15 12:00:00' as date) between '2010-04-01' AND '2010-04-15' -- 1
I haven't checked but I suppose performance is better without casting.
其中CONVERT(VARCHAR(10),datepaid,23)在'2010-04-01'和'2010-04-15'之间
添加此子句:
OR datepaid = '2010-04-15'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.