spires Posted June 24, 2009 Share Posted June 24, 2009 Hi guys. I have a date and time stored in my database: 24/06/2009 09:41:26 What I need to be able to do is see how much time has passed. Example: Todays date & time - Stored date & time = 01d 05h 58min has passed i'm really stuck on this, does anyone of any date function that can do this? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/ Share on other sites More sharing options...
RussellReal Posted June 24, 2009 Share Posted June 24, 2009 see here I just wrote it, no sense in writing it again Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/#findComment-862520 Share on other sites More sharing options...
spires Posted June 24, 2009 Author Share Posted June 24, 2009 Thanks, that look like it will do the trick. One thing though, what is $subEnd. Is it the date and time? e.g 24/06/2009 09:41:26 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/#findComment-862527 Share on other sites More sharing options...
spires Posted June 24, 2009 Author Share Posted June 24, 2009 Hi, Your code works perfect. However, at the moment it counts down, how do I get it to count up? I want to put in a start date, If I do that in your code, I get -3 days, rather than 3 days. Please see: http://www.businessmobiles.com/comcalc/test4.php Your code: $subEnd = date("6/22/2009 11:08:30"); $timeLeft = (strtotime($subEnd) - time()); $mins = floor($timeLeft / 60); $secs = $timeLeft - ($mins * 60); $hours = floor($mins / 60); $mins = $mins - ($hours * 60); $days = floor($hours / 24); $hours = $hours - ($days * 24); echo "You have {$days} days, {$hours} hours, {$mins} minutes and {$secs} seconds remaining of your subscription"; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/#findComment-862532 Share on other sites More sharing options...
thebadbad Posted June 24, 2009 Share Posted June 24, 2009 Firstly, you should store your date-time values in a DATETIME type field (YYYY-MM-DD HH:MM:SS). As far as I know the MySQL functions doesn't recognize your current format, and I know that strtotime() doesn't. Alternatively you'd have to rearrange your format into the above format: $old_format = '24/06/2009 09:41:26'; $parts = explode(' ', $old_format); $parts[0] = implode('-', array_reverse(explode('/', $parts[0]))); $new_format = implode(' ', $parts); Then you could use Russell's code, but rearrange strtotime($subEnd) - time() into time() - strtotime($subEnd), where $subEnd is the date-time value. Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/#findComment-862536 Share on other sites More sharing options...
RussellReal Posted June 24, 2009 Share Posted June 24, 2009 thebadbad beat me to the punch, I was gonna say to switch those values, however, I was bickering with newegg, do you believe they don't let you use alternative mailing addresses with paypal.. so now I need to wait 5 freaking days for a refund!!!!! argh!! so aggravating!! but, what can I do, they gave me a $5 discount on my next purchase.. I'll use the money I save @ the pump.. and get 2 gallons of gas ahahaha.. Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/#findComment-862539 Share on other sites More sharing options...
spires Posted June 24, 2009 Author Share Posted June 24, 2009 Solved. Thanks guys $subEnd = date("m/d/Y H:i:s"); $timeLeft = (strtotime($subEnd) - strtotime($notes_date)); $mins = floor($timeLeft / 60); $secs = $timeLeft - ($mins * 60); $hours = floor($mins / 60); $mins = $mins - ($hours * 60); $days = floor($hours / 24); $hours = $hours - ($days * 24); $diffDate = "{$days}d, {$hours}h, {$mins}min"; Quote Link to comment https://forums.phpfreaks.com/topic/163470-solved-date-and-time-help-needed/#findComment-862602 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.