Jump to content

PHP/Mysql Dates


bigheadedd

Recommended Posts

Hi All,

 

Bit stuck on something I think should be quite simple.

I have a table which includes events that have a state date and end date (startdate, enddate).

 

I've got a search function that pulls out with various criteria etc, however i'm now doing a search by date.

 

For example, an event may start on 1st Jan 2011 and finish on 1st May 2011.

If my search for which events are on on the 2nd February; it should pull the above event out, as it lies inbetween those dates.

 

SELECT * FROM events WHERE ((DAY(events.startdate <= '".date('d',$day)."') AND DAY(events.enddate >= '".date('d',$day)."')) AND MONTH(events.startdate <= '".date('m',$day)."') AND MONTH(events.enddate >= '".date('m',$day)."'))

 

Theres a bunch of other stuff joining tables etc, but you get the idea.

For some reason this isn't working?

 

I've got it working by month, but month AND day is eluding me. I also need to add in the year, but that isn't so important at the moment.

 

Any help would be amazing!

 

Thanks

 

E

 

 

 

Link to comment
Share on other sites

I see, I read that wrong.  I thought you were searching based on today's date.

 

But regardless, TIMESTAMP is essentially the same as DATETIME, so just build a string around the search date, and use that in place of NOW() in the example I posted.

 

$searchdate = $_POST['year'] . "-" . $POST_['month'] . "-" . $_POST['day'] . " 12:00:00";

Link to comment
Share on other sites

Thanks for that; although it still isn't working?

 


$searchdate = date('d',$day)."-".date('m',$day)."-".date('Y',$day)." 00:00:00";
WHERE events.startdate < '".$searchdate."' AND events.enddate > '".$searchdate."'

 

if I add `` to my field names it comes up with invalid field names? Is this my problem?

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.