unknown1 Posted September 1, 2009 Share Posted September 1, 2009 Hello all, I was hoping someone could help me figure out the logic behind a script that deletes a listing automatically after a 90 day time frame. I have no clue on this so any input would be helpful. e.g. how would I say if(todays date == todays date + 90){ } Not familiar with php date function so if someone could help that would be great. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
.josh Posted September 1, 2009 Share Posted September 1, 2009 there is an example of figuring out the date in the future in the manual. date Quote Link to comment Share on other sites More sharing options...
akitchin Posted September 2, 2009 Share Posted September 2, 2009 if you're using MySQL, you can use their date/time functions as well, which are quite robust and handy: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Quote Link to comment Share on other sites More sharing options...
unknown1 Posted September 2, 2009 Author Share Posted September 2, 2009 yes I know that mysql has date time function but I'm having an issue submitting it to the database. e.g. $sql = "insert into table (date) VALUES ('????????')"; I don't understand how to use the function. when I try something like $sql = "insert into table (date) VALUES (date())"; I get an error even when I create a var like $date = date() I still get and error or 00-00-0000 in database. can someone please elaborate on how to use these when submitting to a database... Thanks in advance! Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 2, 2009 Share Posted September 2, 2009 If you encounter errors, print them. What was the error message? Quote Link to comment Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 oh ic it's because i did add a format date("m.d.y") just had date() so it was showing in the database as 00-00-0000 =) lol Any idea of how I would go about counting 30 days from the date("m.d.y")?? Want to set a script up so it will change a listing back to regular after 90 days Quote Link to comment Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 oh ic it's because i did add a format date("m.d.y") just had date() so it was showing in the database as 00-00-0000 =) lol Any idea of how I would go about counting 30 days from the date("m.d.y")?? Want to set a script up so it will change a listing back to regular after 90 days Still showing up as 00-00-000 in database any ideas $date = DATE("m.d.y"); $insetDate = "INSERT INTO sit_details_tmp (rDate) VALUES ('$date')"; works fine on one script but when added to my other page doesn't work. Quote Link to comment Share on other sites More sharing options...
unknown1 Posted September 3, 2009 Author Share Posted September 3, 2009 Got that working... Grrrrrrr stupid little issues. Anyways my biggest issues is counting from date('m.d.y') to 90 days from that time. e.g. $date = date('m.d.y'); if($date == date('m.d.y') + 30){ I know this wont work but does anyone know what I can do to make it work. } Thanks!! Quote Link to comment Share on other sites More sharing options...
.josh Posted September 3, 2009 Share Posted September 3, 2009 there is an example of figuring out the date in the future in the manual. date Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 <?php date_default_timezone_set('America/Los_Angeles'); //Customize this to local time so that your time/days don't get screwed up. $add = array ( 'seconds' => 0, //Number of seconds to add. 'minutes' => 0, //Number of minutes to add. 'hours' => 0, //Number of hours to add. 'days' => 90 //Number of days to add. ); $today = array ( 'd' => date('j'), //Current day. 'm' => date('n'), //Current month. 'y' => date('Y') //Current year. ); $currentDay = mktime(0, 0, 0, $today['m'], $today['d'], $today['y']); //Generates the start of today, in unix time. $futureDay = $add['seconds'] + ($add['minutes'] * 60) + ($add['hours'] * 3600) + ($add['days'] * 86400) + $currentDay; //A bit of magic. print($futureDay); //$futureDay is now the unix timestamp of the day/time in the future. print('<br />'); print(date('l - F jS, Y')); //$futureDay can be formatted however you'd like using date(). Consult php.net/date for more ways to customize. ?> I just wrote this up... does it do what you'd like? Customize the $add array if you need to. Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted September 4, 2009 Share Posted September 4, 2009 does no one like strtotime()???? $today=date('m/d/y'); $theFuture=date('m.d.y',strtotime($today.' + 90 days')); echo $theFuture; if your mysql table field is set to date format then use that format! (Y-m-d) yyyy-mm-dd $today=date('m/d/y'); $theFuture=date('Y-m-d',strtotime($today.' + 90 days')); echo $theFuture; Quote Link to comment Share on other sites More sharing options...
unknown1 Posted September 4, 2009 Author Share Posted September 4, 2009 Thanks guys you're awesome!!! 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.