Jump to content

[SOLVED] Working with dates / queries / calendar


iPixel

Recommended Posts

I've tried to google what i could and im not quite sure how to phrase my search in order to get the results i want.

 

Here's what i'm interested in finding out.

 

I'll have a database with probably a basic 2 field table 

field1[ date ]

field2[ event info ]

 

How would i phrase my query in asking the following

 

SELECT * FROM events WHERE date is greater then today's date LIMIT 0,7

 

I mean will this work?

WHERE date > '09/11/2009' 

in whatever format the date is stored. ?

 

What im aiming to do is to only show  apreview of 1 weeks worth of events and then have  alink to open up a calendar that will show the entire moths worth.  But that's another story. Right now im not sure how to pull the correct rows of data.

 

Thanks Guys!

Link to comment
Share on other sites

Hi,

To start, I presume that your "date" field is in a datetime (or similar) format, otherwise this is going to be hard.

 

This will get results after today (based on server time)

SELECT * FROM events WHERE date >CURDATE()

This should get events after today and up until 7 days times:

SELECT * FROM events WHERE date >CURDATE() AND date<DATE_ADD(INTERVAL,CURDATE(),7 DAY)

Alternatively (better ? ):

SELECT * FROM events WHERE date BETWEEN DATE_ADD(CURDATE(),INTERVAL, 1DAY) AND DATE_ADD(INTERVAL,CURDATE,7 DAY)

You might have to play around with the numbers.... but this might help you in your way :)

 

Chris

 

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.