0

I have a start and end time in milliseconds.

I have to get all the TV series that are ON AIR when the user visits the page.

So I am trying to do this:

if($prog["inizio"] < time() && $prog["fine"] > time()){ array_push($programmazioneFinal[$date."-".$prog["id_canale"]], $prog); } 

The logic is to get only those series whose starting time is lower than now (the serie is already started) and the end time is bigger than now.

For some reasons it is also returning those series that start much later in the day, not just the ones ON AIR now.

What's wrong?

I have added a screenshot of my DB just to make this clearer.

enter image description here

Thank you!

3
  • Are you trying to do it on php side, instead of DB side ? Commented Oct 19, 2015 at 6:22
  • If you are doing it on php side, take my answer... else take @Julio's answer Commented Oct 19, 2015 at 6:29
  • Likely your inizio is wrong and probably 0 (*null* < time() is true) . Thus you get even the ones not started. Check the PHP code that reads the DB. Commented Oct 19, 2015 at 6:33

2 Answers 2

1

In PHP: You can use strtotime. This will give you timestamp value which you can use for comparison

strtotime("now") 

Edit in your code

if($prog["inizio"] < strtotime("now") && $prog["fine"] > strtotime("now")){ array_push($programmazioneFinal[$date."-".$prog["id_canale"]], $prog); } 
Sign up to request clarification or add additional context in comments.

Comments

1

Make your query look like

Select * from ... WHERE UNIX_TIME($your_date_parameter) BETWEEN inizio AND fine 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.