eagleweb Posted October 24, 2007 Share Posted October 24, 2007 I have a date that a member signs up which is input as date(Y-m-d) in the row called 'tempdate'. The member has 15 days to finish some work while there. After that, he can't access the page. When the member goes to his page, I want it to tell him how many days he has left to finish. I have been trying to work with basic math like this $expdate = strtotime("+15 days", $row['tempdate']); $exp_date = date("Y-m-d", $expdate); $days = $exp_date - date("Y-m-d"); obviously this does not work. I have played around with other ideas that also don't work. $expdate = strtotime("+15 days", $row['tempdate']); $today = strtotime(date(Y-m-d)); $days = $expdate - $today; But then i don't know how to change the $days into a number. Does anyone have an example or idea on how to make this work. ONe of my concerns is if the member signs up at the end of the year and his exp date is in the following year. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/74636-solved-math-using-dates/ Share on other sites More sharing options...
eagleweb Posted October 24, 2007 Author Share Posted October 24, 2007 In case anyone wants it, i finally found some code. <?php $results = mysql_query("SELECT * FROM pages WHERE id = '".$_GET['ID']."'", $dbconnect); $row = mysql_fetch_assoc($results); //set your year, month, day, hour, minute, second you want to countdown to. //ONLY CHANGE FROM HERE $tempdate = strtotime($row['tempdate']); $expdate = strtotime("+15 days", $tempdate); $year=date("Y", $expdate); $month=date("m", $expdate); $day=date("d", $expdate); $hour="00"; $minute="00"; $second="00"; //TO HERE. PLEASE DO NOT CHANGE ANY OTHER BIT OF CODE $time=mktime($hour, $minute, $second, $month, $day, $year); $timecurrent=date('U'); $cdtime=$time-$timecurrent; $cdminutes=$cdtime/60; $cdhours=$cdtime/3600; $cddays=$cdhours/24; $cdmonths=$cddays/30; $cdyears=$cddays/365; echo "Your page can be viewed for ".number_format($cddays)." more days."; ?> As you can see, you can echo years, months, days, hours, minutes, and seconds. I hope this helps someone else. Quote Link to comment https://forums.phpfreaks.com/topic/74636-solved-math-using-dates/#findComment-377339 Share on other sites More sharing options...
Barand Posted October 24, 2007 Share Posted October 24, 2007 SELECT (TO_DAYS(tempdate) + 15 - TO_DAYS(CURDATE()) AS daysleft FROM tablename Quote Link to comment https://forums.phpfreaks.com/topic/74636-solved-math-using-dates/#findComment-377341 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.