viko
viko

Reputation: 533

How to return the difference between two column values?

I have tables when there are 2 columns. The first column is the start time work shop. The second column is the hour of the completion of the work shop.

Examples:

id | start | stop
1  |    10 | 18
2  |     8 | 20
3  |    11 | 21

I need a list of stores that are now working.

Now hour = 10
start >= '".$now_hour."' and stop <= '".$now_hour."'

I see only shop id=1, but shop id=2 also should be listed.

Upvotes: 0

Views: 86

Answers (2)

Ravinder Reddy
Ravinder Reddy

Reputation: 23982

You can use between clause with your value on nowHour

where ? between start and stop

? is place holder for nowHour value.
Use prepared statement in your scripting language to bind the placeholder.

Upvotes: 1

Tom Mac
Tom Mac

Reputation: 9853

Logic is incorrect?

`start` <= '".$now_hour."' and `stop` >= '".$now_hour."'

Upvotes: 3

Related Questions