0

The table that called "events" has 2 paranetes. StartTime and EndTime that contain UNIX time.

ID   StartTime    EndTime
1   1522530000   1532590000

i got 2 values from the user that contain Unix Times.

$start = 1522530000;
$end = 1532590000;

Im trying to get the rows between the times that i got:

SELECT * FROM `events` WHERE (StartTime <= '$start' AND EndTime >= '$end') 

And its work but not always, like:

$start = 1530392400;
$end = 1534107599;

what can i do?

Razdom
  • 137
  • 12
  • 1
    it says `StartDate` in your query and `StartTime` in your question – nimmneun Apr 30 '18 at 19:46
  • See https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query – Strawberry Apr 30 '18 at 19:46
  • @Syscall if its 1522530000 1526245199 its work but if it 1530392400 1534107599 its doesnt work – Razdom Apr 30 '18 at 19:52
  • debug the problem; there's something going on you haven't showed. from what you've shown, the query should be returning the row, as a demonstration http://sqlfiddle.com/#!9/588771/1 so there's something else going on. – spencer7593 Apr 30 '18 at 19:52
  • 2
    The conditions in the query are looking for rows in the table that have *complete* overlap with the two provided times... the beginning of the event in the table is on or before the provided start, and the end of the event in the table is on or after the provided end. (The specification is vague ... "between 2 times from 2 times" so we are going with the specification as the one that's provided in the SQL. perhaps you are meaning to check some other condition; for example, are you intending to look for a partial overlap? (we're just guessing here.) – spencer7593 Apr 30 '18 at 19:56
  • @spencer7593 Yes I mean to partial overlap – Razdom Apr 30 '18 at 20:00
  • a partial overlap would be `t.endtime >= :start and t.starttime <= :end`. (And this isn't specifically a SQL problem... – spencer7593 Apr 30 '18 at 20:07

0 Answers0