Johns3n Posted July 27, 2010 Share Posted July 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/208988-problem-with-selecting-specific-dates/ Share on other sites More sharing options...
Johns3n Posted July 27, 2010 Author Share Posted July 27, 2010 I just realized i wrote the date format wrong It is "dd/mm/yyyy" But the overall problem still persists, so any help would still be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/208988-problem-with-selecting-specific-dates/#findComment-1091622 Share on other sites More sharing options...
PFMaBiSmAd Posted July 27, 2010 Share Posted July 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/208988-problem-with-selecting-specific-dates/#findComment-1091660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.