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? Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/ 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 Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283710 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()); ?> Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283714 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 =\ Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283726 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); Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283730 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"? Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283738 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 Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283745 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 Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283747 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. Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283761 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 Link to comment https://forums.phpfreaks.com/topic/57367-solved-show-older-entries/#findComment-283762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.