I made the following example and it worked:
CREATE TABLE tabela (
UserName varchar(100),
StartDate datetime,
EndDate datetime
);
insert into tabela (UserName, StartDate, EndDate)
values
('eu', '2014-02-25 04:00:00', '2014-02-25 05:00:00'),
('me', '2014-02-25 03:30:00', '2014-02-25 04:30:00'),
('jo', '2014-02-25 03:00:00', '2014-02-25 04:00:00');
SELECT *
FROM tabela AS x
WHERE CONVERT_TZ('2014-02-25 18:27:30','+11:00','-03:00')
BETWEEN x.StartDate AND x.EndDate
Note that the time returned by the code:
CONVERT_TZ('2014-02-25 18:27:30','+11:00','-03:00')
IS:
February, 25 2014 04:27:30+0000
You’re probably not getting the result because:
- The columns
StartDate
and EndDate
are of the type DATE
and have no time information. In this case, you can use the function date()
to remove the time at the time of comparison.
- There are no records whose date/time returned is within the range. Maybe you were expecting another result.
If your case is item #1, do so:
SELECT *
FROM tabela AS x
WHERE date(CONVERT_TZ('2014-02-25 18:27:30','+11:00','-03:00'))
BETWEEN x.StartDate AND x.EndDate
Really I have to get the date and time, my fields are like datetime... I’m going to test this one based on your, http://sqlfiddle.com/#! 8/8afd8/1
– Aron
Still not working, look at the example I used. http://sqlfiddle.com/#! 2/dd4c1b/1/0
– Aron
@Aronpeyrouter The result is correct, it is the case of item #2 of my answer. There is no interval that covers the past value. Look at this sqlfiddle, I searched one by one and there’s nothing.
– utluiz
@Aronpeyroterdoso Now, if you change the time of
'2014-02-25 18:27:30'
for'2014-02-25 18:27:27'
, then you have one result, just to quote an example.– utluiz
True, THANK YOU. I will remove the seconds from the search field.
– Aron