Jump to content

help with dates


dadamssg

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.