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 Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/ 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? Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-845896 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". Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-845918 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. Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-845919 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 Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-845922 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. Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-845926 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 Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-845929 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!!!!!"; } Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-846408 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() Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-846411 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 Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-846424 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'; } Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-846425 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? Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-846638 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. Link to comment https://forums.phpfreaks.com/topic/160286-help-with-dates/#findComment-846642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.