CloudSex13 Posted March 4, 2009 Share Posted March 4, 2009 Hey there - I was wondering if it was possible to, for example, take today's date via PHP and store it as a variable, and then run a query to see if it matches a deadline date in a database? It sounds like it'll work, but just making sure. And if that does work, is there a way to also accept matches where today's date could match a deadline even if it's up to 7 days later in the database compared to the current date? I suppose I'm asking if there's a certain function to check the date range between the deadline and today's date, or if there's a certain method I should approach for this. Thank you if so. Best - Link to comment https://forums.phpfreaks.com/topic/147945-solved-matching-todays-date-with-a-deadline-field-in-the-database/ Share on other sites More sharing options...
rhodesa Posted March 4, 2009 Share Posted March 4, 2009 short answer is YES. your description is a little too vague to provide a specific answer though. by the sounds of it, you should have a column in your table (let's call it 'deadline') of the dataype DATE. Then, you can use that in your SQL query...for instance: All the entries where the deadline has passed: SELECT * FROM tablename WHERE deadline < NOW() NOW() in MySQL refers to the current date/time All the entries for a specific day: SELECT * FROM tablename WHERE deadline = '2009-03-01' All the entries where the deadline is this month: SELECT * FROM tablename WHERE deadline BETWEEN '2009-03-01' AND '2009-03-31' Link to comment https://forums.phpfreaks.com/topic/147945-solved-matching-todays-date-with-a-deadline-field-in-the-database/#findComment-776502 Share on other sites More sharing options...
Boo-urns Posted March 4, 2009 Share Posted March 4, 2009 Now if you want to match it via next week or any given possibility Next Thursday etc... use strtotime http://us3.php.net/strtotime Link to comment https://forums.phpfreaks.com/topic/147945-solved-matching-todays-date-with-a-deadline-field-in-the-database/#findComment-776505 Share on other sites More sharing options...
CloudSex13 Posted March 4, 2009 Author Share Posted March 4, 2009 I see! Thanks rhodesa and Boo-urns. I'm just confused on, in example, the variable $nextweek. Would I use strtotime there? $today = date("F j, Y"); $nextweek = mysql_query("SELECT * FROM Tasks WHERE Deadline BETWEEN '$today' AND '$nextweek'"); EDIT: The variable $today would be unecessary technically, as you mentioned NOW() could be used. So it'd be: $today = date("F j, Y"); $nextweek = mysql_query("SELECT * FROM Tasks WHERE Deadline BETWEEN NOW() AND '$nextweek'"); Link to comment https://forums.phpfreaks.com/topic/147945-solved-matching-todays-date-with-a-deadline-field-in-the-database/#findComment-776510 Share on other sites More sharing options...
rhodesa Posted March 4, 2009 Share Posted March 4, 2009 yes, you could use strtotime(): //the strtotime() part gives one week from today as a timestamp //Then date() formats it into MySQL DATE format $nextweek = date('Y-m-d',strtotime('+1 week')); mysql_query("SELECT * FROM Tasks WHERE Deadline BETWEEN NOW() AND '$nextweek'"); you should be able to use MySQL functions too though (instead of strtotime/date) Link to comment https://forums.phpfreaks.com/topic/147945-solved-matching-todays-date-with-a-deadline-field-in-the-database/#findComment-776518 Share on other sites More sharing options...
CloudSex13 Posted March 4, 2009 Author Share Posted March 4, 2009 Ahh, that makes sense - I was just researching up on strtotime. Thanks rhodesa for that, though. I'll look into the MySQL functions, too. Thanks again. :] Link to comment https://forums.phpfreaks.com/topic/147945-solved-matching-todays-date-with-a-deadline-field-in-the-database/#findComment-776521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.