Hobbyist_PHPer Posted May 8, 2011 Share Posted May 8, 2011 Hi all, I am trying to figure out how to add 60 days to a mysql stored DATE, then subtract the current date from that date to see how many days there are... Its for a 60 day trial and when they signed up, it put the date in which they signed up in the database table... Here's what I have, but it's not working... But I can't get it to add 60 days to a mysql stored DATE,... then of course I have to figure out how to do the subtraction... $CustomerSaasDateStarted = $row['CustomerSaasDateStarted']; $CustomerSaasDateStartedPlusSixtyDays = date("Y-m-d", strtotime($CustomerSaasDateStarted, "+60 days")); // Test Output echo 'Date Trial Started: '.date("M d, Y", strtotime($CustomerSaasDateStarted)); echo '<br />'; echo '60 days from Date Trial Started: '.date("M d, Y", strtotime($CustomerSaasDateStartedPlusSixtyDays)); echo '<br />'; Quote Link to comment https://forums.phpfreaks.com/topic/235865-php-time/ Share on other sites More sharing options...
Hobbyist_PHPer Posted May 8, 2011 Author Share Posted May 8, 2011 Ok, figured out how to add 60 days to a mysql date... $CustomerSaasDateStartedPlusSixtyDays = date('M d, Y', strtotime($CustomerSaasDateStarted.' '.'+60 days')); Now just need to figure out how to subtract the current date from that... will post code if I figure it out... Quote Link to comment https://forums.phpfreaks.com/topic/235865-php-time/#findComment-1212455 Share on other sites More sharing options...
Hobbyist_PHPer Posted May 8, 2011 Author Share Posted May 8, 2011 Cannot seem to get a grip on this whole subtracting 2 dates things... I need to find out how many days are left from the subtraction... This gives the wrong output, but like a month's worth... $CustomerSaasDateStarted = $row['CustomerSaasDateStarted']; $CustomerSaasDateStartedPlusSixtyDays = date('Y-m-d', strtotime($CustomerSaasDateStarted.' '.'+60 days')); $TheCurrentDate = date('Y-m-d'); $TheCurrentDate = new DateTime($TheCurrentDate); $CustomerSaasDateStartedPlusSixtyDays = new DateTime($CustomerSaasDateStartedPlusSixtyDays); $DifferenceInterval = $TheCurrentDate->diff($CustomerSaasDateStartedPlusSixtyDays); echo $DifferenceInterval->d.' Days Remaining on Trial<br /><br /> Quote Link to comment https://forums.phpfreaks.com/topic/235865-php-time/#findComment-1212462 Share on other sites More sharing options...
PFMaBiSmAd Posted May 8, 2011 Share Posted May 8, 2011 You can do this all as part of your query - SELECT DATEDIFF(DATE_ADD(CustomerSaasDateStarted, INTERVAL 60 DAY),CURDATE()) as days_remaining A negative value would indicate the current date is past the end of the trial. A positive value would indicate the trial is still in effect. Quote Link to comment https://forums.phpfreaks.com/topic/235865-php-time/#findComment-1212464 Share on other sites More sharing options...
Hobbyist_PHPer Posted May 8, 2011 Author Share Posted May 8, 2011 You can do this all as part of your query - SELECT DATEDIFF(DATE_ADD(CustomerSaasDateStarted, INTERVAL 60 DAY),CURDATE()) as days_remaining A negative value would indicate the current date is past the end of the trial. A positive value would indicate the trial is still in effect. Thank you, that worked perfectly, never thought to do it in the query... Quote Link to comment https://forums.phpfreaks.com/topic/235865-php-time/#findComment-1212500 Share on other sites More sharing options...
Hobbyist_PHPer Posted May 8, 2011 Author Share Posted May 8, 2011 Actually, had to make one minor change to make the amount of days come out right, I didn't notice it at first until I started changing the date in which they signed up... (60 - DATEDIFF(DATE_ADD(CustomerSaasDateStarted, INTERVAL 60 DAY),CURDATE())) as DaysRemaining Quote Link to comment https://forums.phpfreaks.com/topic/235865-php-time/#findComment-1212520 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.