dadamssg Posted May 30, 2009 Share Posted May 30, 2009 im trying to do is find out if the event im querying is happening today. i had this $now = time() if(strtotime($row['start']) > $now and strtotime($row['end'] < $now)) { echo "Its today!!!!!"; } but its wrong, not only because of the syntax but that deals with time...the event can start a month ago if it ends today or later..or it can start today and end today or end in a month....i just want to find out if any part of it is happening the current date...thanks Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 if(strtotime($row['start']) > $now and strtotime($row['end'] < $now)) Should be: if(strtotime($row['start']) > $now and strtotime($row['end']) < $now) Right? Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 Ken fixed the syntax error, but your logic should be the other way around. Currently you say; if the start happens after now and the end happens before now, do this. It should be: if(strtotime($row['start']) < $now and strtotime($row['end']) > $now) "It has started and hasn't ended". Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 That's more like it had started and has not ended. if(strtotime($row['start']) <= $now and strtotime($row['end']) > $now) Much more like it. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 Sure, but I'm assuming $row['start'] and $row['end'] are datetime values (YYYY-MM-DD HH:MM:SS), so I figured that one second wouldn't matter much Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 30, 2009 Share Posted May 30, 2009 They better not be. $now = time(), so $row['start'] and $row['end'] should be in seconds. Which reminds me. Syntax error on that line $now = time(). You need a semi-colon after it. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 They better not be. $now = time(), so $row['start'] and $row['end'] should be in seconds. No, they are run through strtotime() that expects the datetime format, and returns a timestamp. But I'm sure you just overlooked that. Edit: In either case, while your comparison operator <= is logically correct, it will still only make a difference if the script is run at the same second the event is set to start Quote Link to comment Share on other sites More sharing options...
dadamssg Posted May 31, 2009 Author Share Posted May 31, 2009 hey guys, thanks for the advice...but i don't think thats gonna gonna do what i want it to do...cause say its 3:20pm right now, but if i have an event that starts at 4:00pm today and ends at 5:30pm today it won't work....thanks for lookin at it again $now = time(); if(strtotime($row['start']) <= $now and strtotime($row['end']) > $now) { echo "Its today!!!!!"; } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 31, 2009 Share Posted May 31, 2009 Why not use MySQL? (Not tested.) SELECT * FROM tablename WHERE DATE_FORMAT(start, '%Y-%m-%d') <= CURDATE() AND DATE_FORMAT(end, '%Y-%m-%d') >= CURDATE() Quote Link to comment Share on other sites More sharing options...
dadamssg Posted May 31, 2009 Author Share Posted May 31, 2009 cause im pulling up and displaying all the events...so i want to put a symbol or something next to the events that are occurring today Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 31, 2009 Share Posted May 31, 2009 You can still use SQL: select *, now() between start_tm and end_tm as `is_today` from `thetable` where ... Then your $row variable should have an index is_today: if( $row['is_today'] ) { echo 'it happens today'; } Quote Link to comment Share on other sites More sharing options...
dadamssg Posted June 1, 2009 Author Share Posted June 1, 2009 could you explain that? i don't understand the start_tm and end_tm part and how would output the variables? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 1, 2009 Share Posted June 1, 2009 I believe roopurt18 just used tm to represent time. So start_tm = start_time or whatever the start column name is. It was just an example. Similar situation for end_tm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.