jarvis Posted July 21, 2009 Share Posted July 21, 2009 Hi All, Hope some kind soul can help!? I've a users table in a CMS i'm building. This users table has a registration_date that stores data in datetime format. When a user registers, they can select whether they want a normal or premium account. As such, they will need to pay for the premium account. I've built a script which list all users and the date joined using $query = "SELECT CONCAT(last_name, ', ', first_name) as name, DATE_FORMAT(registration_date,'%d %M %Y') as date, email FROM users ORDER BY $order_by LIMIT $start, $display"; I then show the date next to the username. All's ok so far. What I want to do is set it so that if a year has passed since the join date, an email is sent reminding them of payment is due and 30 days prior to this, a warning email is sent. I know a cron jobs used for automating, however, at the mo, I can't even get the date difference working. This is the code I've got so far: $todays_date = time(); echo $todays_date .' todays'; echo '<hr/>'; $joined_date = mktime($row['date']); echo $joined_date .' joined'; echo '<hr>'; $dateDiff = $todays_date - $joined_date; echo $dateDiff .' date diff'; echo '<hr>'; $time_convert = (60*60*24); echo $time_convert . ' time convert'; $fullDays = floor($dateDiff/$time_convert); echo '<hr>'; echo "Differernce is $fullDays days"; It keeps saying 0 days though! Once I can get the date calc working I can then start working on the email code & then a cron job to automate it all. Any help is much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/ Share on other sites More sharing options...
ignace Posted July 21, 2009 Share Posted July 21, 2009 mktime($row['date']); should be: $joined_date = strtotime($row['date']); http://be.php.net/mktime requires it's parameters to be integers and if they are not they are converted to them abiding by the type conversion rules. print (int) "hello world"; // 0 Thus: mktime($row['date']); equals mktime(0); which equals the current date in seconds. Therefor $joined_date ~ $todays_date. Then you convert to days which is 0 as the difference between today and today is 0 Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-879698 Share on other sites More sharing options...
jarvis Posted July 22, 2009 Author Share Posted July 22, 2009 Thanks ignace, do I need to do any of the following: echo $dateDiff .' date diff'; echo '<hr>'; $time_convert = (60*60*24); echo $time_convert . ' time convert'; $fullDays = floor($dateDiff/$time_convert); As changing that one line makes the following: Differernce is 14447 days Which isn't right. Sorry! :-\ Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-880117 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 $todays_date = time(); echo $todays_date .' todays'; echo '<hr/>'; $joined_date = strtotime('01 Juli 2009'); echo $joined_date .' joined'; echo '<hr>'; $dateDiff = $todays_date - $joined_date; echo $dateDiff .' date diff'; echo '<hr>'; $time_convert = (60*60*24); echo $time_convert . ' time convert'; $fullDays = floor($dateDiff/$time_convert); echo '<hr>'; echo "Differernce is $fullDays days"; gives me (on 22 Juli 2009): 1248271225 todays -------------------------- 1246446540 joined -------------------------- 1824685 date diff -------------------------- 86400 time convert -------------------------- Differernce is 21 days Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-880320 Share on other sites More sharing options...
jarvis Posted July 22, 2009 Author Share Posted July 22, 2009 Hi ignace, Many thanks for the reply. That does seem to work until I change: $joined_date = strtotime('01 Juli 2009'); To: $joined_date = strtotime($row['date']); I'm setting $joined date as follows: DATE_FORMAT(registration_date,'%d %M %Y') as date $joined_date = $row['date']; Do I need to alter this as registration_date is in my db as date_time Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-880342 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 Many thanks for the reply. That does seem to work until I change: $joined_date = strtotime($row['date']); What prints: print $row['date'];? Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-880357 Share on other sites More sharing options...
jarvis Posted July 22, 2009 Author Share Posted July 22, 2009 If I print that line from the db // Retrieve the date the member joined $joined_date = $row['date']; echo $joined_date .'- joined date<br/>'; I get 22 July 2009- joined date Thanks and apologies Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-880374 Share on other sites More sharing options...
jarvis Posted July 27, 2009 Author Share Posted July 27, 2009 Sorry to bump, wondered if someone could point out the obvious! many thanks Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-883936 Share on other sites More sharing options...
ignace Posted July 28, 2009 Share Posted July 28, 2009 If I print that line from the db // Retrieve the date the member joined $joined_date = $row['date']; echo $joined_date .'- joined date<br/>'; I get 22 July 2009- joined date Thanks and apologies What does it print if you execute the code? Still 14447? Quote Link to comment https://forums.phpfreaks.com/topic/166807-solved-php-date-issue-for-auto-payment-reminder/#findComment-884783 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.