lalabored Posted June 27, 2007 Share Posted June 27, 2007 I have a MySql table with the field "sentdate". How could I set up a query that selects only entries that have a sentdate that is for example 30 days old? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 is sentdate a timestamp/date field? if so then look into date functions. You can use any of your || && != > < operators for comparisons of dates as long as your date is in the same format as the dates in the mysql database this is a good reference to dates http://www.w3schools.com/php/php_ref_date.asp Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 27, 2007 Share Posted June 27, 2007 Try this: <?php mysql_query("SELECT * FROM `table` WHERE `sentdate` = Date() - 30")or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
lalabored Posted June 27, 2007 Author Share Posted June 27, 2007 Try this: <?php mysql_query("SELECT * FROM `table` WHERE `sentdate` = Date() - 30")or die(mysql_error()); ?> That didn't work =S I tried using this... $old = mktime(0, 0, 0, date("m"), date("d")-1, date("Y")); $q = "SELECT * FROM `p_messages_sent` WHERE UNIX_TIMESTAMP(sentdate) < $old"; $rs = mysql_query($q); ..to get rows that were older than 1 day (because I didn't have anything older than 30 days) but that didn't work =\ Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 that's because $old isn't a date its a data object so to speak. You need to say $old = date(format you like, $old); Quote Link to comment Share on other sites More sharing options...
lalabored Posted June 27, 2007 Author Share Posted June 27, 2007 that's because $old isn't a date its a data object so to speak. You need to say $old = date(format you like, $old); But how would I compare something made from date() to a MySql date that's like this "0000-00-00 00:00:00"? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 I use a mysql date field and this snippet $tempdate = mktime(0,0,0,date("m"),date("d")-1,date("Y")); $tempdate = date("Y-m-d", $tempdate); edit changed the day to -1 for your case Quote Link to comment Share on other sites More sharing options...
rhyspaterson Posted June 27, 2007 Share Posted June 27, 2007 Yeah date is pretty configurable, pretty sure you can modify it's output to match whatever you want Quote Link to comment Share on other sites More sharing options...
lalabored Posted June 27, 2007 Author Share Posted June 27, 2007 I use a mysql date field and this snippet $tempdate = mktime(0,0,0,date("m"),date("d")-1,date("Y")); $tempdate = date("Y-m-d", $tempdate); edit changed the day to -1 for your case Ooh! I see, thank you very much. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 did that work? if so mark your topic solved please Quote Link to comment 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.