simcoweb Posted February 17, 2007 Share Posted February 17, 2007 Summary: * ad posters can create one ad per every 7 days * their email address is the user id i'm working off of to determine if they've already submitted an ad * say they try to submit an ad 3 days after submitting a previous ad * I want a message to say 'You can not post an ad until Saturday... blah blah'. I need to find the date they submitted their current ad which is no problem since it's inserted into the database when they created the ad. Now, it's 3 days later and they want to submit another. I need to determine if it's been 7 days or not and, if not, display an error and, if so, let it go through. Here's what I have but it doesn't work (or why else would I be posting... eh? lol) <?php $date1 = '11/25/06'; $date2 = "now"; $start = strtotime($date1); $end = strtotime($date2); $days = ($date2 - $date1) / (60*60*24); $diff = number_format($days); echo $diff; ?> This is not 100% accurate to how it would actually be written but it's my working model to get the math right. The logic here line by line is: 1. get the date from the current db entry 2. get today's date 3. calculate the time stamp for the date of their ad posting 4. calculate the time stamp for today 5. calculate the difference 6. print the difference Obviously something is not right as it returns -0 as the value. Help anyone? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 17, 2007 Share Posted February 17, 2007 This is actually something that is more reliable to perform in a mysql query as mysql's support for date calculations is better than php's.... have a read of this page http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html domewhere in there will be an example doing exactly what you need... Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 17, 2007 Share Posted February 17, 2007 According to SELECT TO_DAYS( '2007-02-17' ) - TO_DAYS( '1976-07-03' ) I am 11,186 days old.... Quote Link to comment Share on other sites More sharing options...
printf Posted February 17, 2007 Share Posted February 17, 2007 datediff() SELECT DATEDIFF(NOW(), date_column) AS days FROM table WHERE ...; printf 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.