Jump to content

sql date >= today? need help


Aezel

Recommended Posts

I've made a site for my game guild. On the pages i have a section where upcoming guild events are displayed with the following query:

SELECT * from eventsWHERE month >= MONTH( NOW())AND day >= DAY(NOW())ORDER BY month, day LIMIT 4

The values for month are 1-12 (Jan-Dec) and the values for day are 1-31. Year is not posted so irrelevant to this code at the moment.The values are posted with a html form, <select> (<option>) to be exact. I'm new to SQL/PHP and couldn't think of another way to post future dates into the sql database.This query worked fine until now. I posted a new event that will take place next month, April 1st. It doesn't show up on the events section of the webpage.Can somebody please show me a query that will make all upcoming events show up on the pages? Even when the month is different?To me the query looks like it should display all events that are later than the current date.. I'm really lost here.Any help would be greatly appreciated.

Link to comment
Share on other sites

You should include the year. In fact you should just create a date field in your database and store the actual full date.then you can do this

$sql = "SELECT * FROM events WHERE thedate >= " . getdate() . " ORDER BY thedate LIMIT 4";

Link to comment
Share on other sites

Thx for your reply.By actual full date you mean with $date? That would be the posting date then right?It needs to be ordered chronologically by future dates cuz the upcoming events are all in the future. I couldn't think of another way to post future dates with the html form me and the co-leaders of the guild use.So $date wouldn't help me too much; when someone else adds an event that is to take place 2 days earlier it would still be displayed after the other event, even tho the other event will take place later (not chronologically displayed). I hope this makes sense lol.Maybe u know of a better way to post future dates to the sql database so I can indeed work with "getdate". Or am I just missing your point?The page in question

Link to comment
Share on other sites

You can set your database field to type date or datetime. Then you can insert a date (02/11/2007) into the database. You don't need the $date function for that, just to get today's date when selecting future days to see if the date in the datebase is greater than today's date.If you need me to further explain this just ask and I can write a short example. :)

Link to comment
Share on other sites

I now have 2 fields (both int(2) ), one for month and one for day. That's because on the form where we post the events, there's a dropdownbox for both fields. One with values 1-12 for month and one for day (values 1-31).So I should drop these 2 fields and make a new one (type: date), and then we should simply type the date of the event into a textfield at the form?Is that what you mean I should do?

Link to comment
Share on other sites

You can set your database field to type date or datetime. Then you can insert a date (02/11/2007) into the database. You don't need the $date function for that, just to get today's date when selecting future days to see if the date in the datebase is greater than today's date.If you need me to further explain this just ask and I can write a short example. :)

Yes please if it's not too much trouble cause I'm not sure what u mean.
Link to comment
Share on other sites

Nvm I fixed it.I added an <input> field to the form called raidday where we enter the date YYYY-MM-DD.Then I made the new raidday field (date) in the database and it works fine now with this query:

SELECT * from events WHERE raidday>=date( NOW()) ORDER BY month, day LIMIT 4

Thanks again for your help :).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...