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
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
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
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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.