pufAmuf
pufAmuf

Reputation: 7805

Setting Date and Time Variables in PHP

I'm trying to build a MySQL select statement to get all data out of a MySQL table (events) for the current day that a visitor is seeing the page. However, by current day - I mean between 6AM and 5:59AM the next day. The reason being that events last till early morning the next day, I want the page to show events that are still taking place when a person views the website - at 1AM for example.

I have this code so far

SELECT * FROM events WHERE %DATE_START_SELECTED% <= start_datetime AND end_datetime < %DATE_END_SELECTED%

However I'm baffled as to how I'd set the %DATE_START_SELECTED% and %DATE_END_SELECTED% in php. Any Ideas please :)?

Thanks

Upvotes: 0

Views: 131

Answers (2)

Narayan Singh
Narayan Singh

Reputation: 1232

use this code

 SELECT * FROM events WHERE %DATE_START_SELECTED% between to_date(start_datetime AND end_datetime)

Upvotes: 2

Marek D.
Marek D.

Reputation: 11

Can you solve your problem with this simple sql statement?

SELECT * FROM events 
WHERE start_datetime >=  UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) 
AND end_datetime < UNIX_TIMESTAMP(CURRENT_TIMESTAMP()  + INTERVAL  24*60*60-1 SECOND) 

Upvotes: 1

Related Questions