hosker Posted December 13, 2012 Share Posted December 13, 2012 I have searched the forum, but I did not finda post that would help me with my issue. I have a cron job that I am going to run every monday, however, I do not want to type out all of the dates into an if else statement, but would rather write it in a loop. I want to pull the date from the database table, which is always going to be a Thursday( and an ocassional Wednesday), and check to see if the Monday prior is todays date, and if it is, I want to pull the file tournament_id from my database and insert it into a variable. How can this be done? The date is in the following format: YYYY-MM-DD. Thanks in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/271941-php-date-help/ Share on other sites More sharing options...
Muddy_Funster Posted December 13, 2012 Share Posted December 13, 2012 do it in the query using a DATEDIFF() in the where clause Quote Link to comment https://forums.phpfreaks.com/topic/271941-php-date-help/#findComment-1399103 Share on other sites More sharing options...
hosker Posted December 15, 2012 Author Share Posted December 15, 2012 I am using strtotim() which I can get to work outside of my SQL query. How would I mkae this SQL statement work" $today = strtotime(date('2013-01-07')); $sql = "SELECT * FROM tournaments_2013 WHERE (strtotime('Last Monday', start_date) = $today)"; $result = mysql_query($sql); print_r($result); exit; echo "<table><tr><th>Tournament</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>" . $row['tournament_id'] . "</td></tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/271941-php-date-help/#findComment-1399496 Share on other sites More sharing options...
Christian F. Posted December 15, 2012 Share Posted December 15, 2012 strtotime () is a PHP function, not an MySQL function. For MySQL you'll need to use MySQL's datetime functions. Quote Link to comment https://forums.phpfreaks.com/topic/271941-php-date-help/#findComment-1399507 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.