Jump to content

Recommended Posts

First off! I am very sorry if I post this in the wrong forum, but I am having trouble with writing a SQL query in my PHP files, that I am doing for a project.

 

I am writing a small CMS, and I need it to select all the events which's end date is less than or equal to the current server time. But using dates in PHP is really doing my head in, read alot of articles about the subject using Google but unfortunally they didn't help me as much as i had hoped :(

 

Thats now why I turn to you folks at Phpfreaks.com

 

Event table:

ID - Title - Category - Event_date - End_date - End_time

1    Blah!  Music        06/08/10      07/08/10  16:50:00

 

As you can see the end date is in the format "dd/mm/yy" and the end time is in "hh:mm:ss"

 

So i am thinking that the SQL query must be something like (mind im a complete novice at PHP so this is just something that spawned top of my head!)

 

$events_data = mysql_query("SELECT * FROM events WHERE End_date >= CURDATE(dd/mm/yy) AND End_time >= CURTIME(hh:mm:ss)" );

 

Unfortunally this doesn't work for me, so i hope you guys can help me in the right direction.

 

btw I would be really sad if I would have to change the date format in Database because I already did a huge amount of code around that in this little CMS of mine.

 

But looking forward to the help! and thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/208988-problem-with-selecting-specific-dates/
Share on other sites

Your first step will be to use an actual mysql DATE or DATETIME data type to store your dates and date/times in.

 

Once you do that, you can perform greater-than/less-than comparisons and ordering in your query.

 

The YYYY-MM-DD date format exists for several reasons, the most import one is that the fields that make it up are left-to-right, most significant digit to least significant digit, which is what is necessary to compare dates by magnitude.

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.