Kemik Posted August 20, 2007 Share Posted August 20, 2007 Hello, If I want to display a message saying "Ready" if the $datemade variable is more than 48 hours ago but $datemade is stored as a datetime in the database how would I do it? I can create the code using strtotime("-2 days") and it works to see if the $datemade is more or less than 2 days but I cannot get it to show how many hours are left. Basically, if ($datemade > 48 hours){ echo "Ready"; } else { echo $hours . "hours " . $mins . "mins remaining until ready."; } Quote Link to comment https://forums.phpfreaks.com/topic/65888-solved-subtracting-datetime/ Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 try if ($datemade >= ($datemade+(2*24*60*60) )){ Quote Link to comment https://forums.phpfreaks.com/topic/65888-solved-subtracting-datetime/#findComment-329360 Share on other sites More sharing options...
Kemik Posted August 20, 2007 Author Share Posted August 20, 2007 Solved. After some digging around I found some info and come up with the following: <?php // $datejoined can be replaced with which ever datetime variable you want. The following code checks if the user joined the site 48 hours ago (2 days) and if so, shows an image. If not, displays the remaining hours. $days2 = strtotime("-2 days"); if (strtotime($datejoined) < $days2) { $eligible = '<img src="'.base_url().'images/icons/yes.png" width="16" height="16" alt="Ready To Play" />'; } else { $remaining = intval((strtotime($datejoined) - $days2)/3600); $eligible = 'In '.round($remaining).' hours'; } ?> Hope this helps someone in the future. Quote Link to comment https://forums.phpfreaks.com/topic/65888-solved-subtracting-datetime/#findComment-329374 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.