will35010 Posted May 22, 2014 Share Posted May 22, 2014 Hello, I'm trying to use strtotime to add time to a mysql type timestamp. Any help would be appreciated. I think I have tunnel vision from looking at it when I know it has to be something obvious...lol $start = "2014-05-22 09:16:24"; $type = 30; $endtime = date($start,strtotime("+ '.$type.' minutes")); echo "End: ".$endtime."</br>Start: ".$start; Right now it returns: End: 2014-05-22 09:16:24 Start: 2014-05-22 09:16:24 Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/ Share on other sites More sharing options...
Ch0cu3r Posted May 22, 2014 Share Posted May 22, 2014 (edited) The third line needs to be $endtime = date('Y-m-d H:i:s',strtotime($start, "+$type minutes")); No need for the quotes Edited May 22, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/#findComment-1480443 Share on other sites More sharing options...
will35010 Posted May 22, 2014 Author Share Posted May 22, 2014 The third line needs to be $endtime = date('Y-m-d H:i:s',strtotime($start, "+$type minutes")); No need for the quotes I'm afraid that returns the same thing $start = "2014-05-22 09:16:24"; $type = 30; $endtime = date('Y-m-d H:i:s',strtotime($start, "+$type minutes")); echo "End: ".$endtime."</br>Start: ".$start; End: 2014-05-22 09:16:24 Start: 2014-05-22 09:16:24 Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/#findComment-1480445 Share on other sites More sharing options...
Ch0cu3r Posted May 22, 2014 Share Posted May 22, 2014 Brain fart moment . It should be like $endtime = date('Y-m-d H:i:s', strtotime("+$type minutes", strtotime($start))); Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/#findComment-1480447 Share on other sites More sharing options...
Solution will35010 Posted May 22, 2014 Author Solution Share Posted May 22, 2014 Brain fart moment . It should be like $endtime = date('Y-m-d H:i:s', strtotime("+$type minutes", strtotime($start))); That worked! It was about to drive me insane...lol. Thank you Ch0cu3r! Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/#findComment-1480448 Share on other sites More sharing options...
Barand Posted May 22, 2014 Share Posted May 22, 2014 if those values are in the database you can do it the query SELECT start , type , start + INTERVAL type MINUTE as end FROM testtime; +---------------------+------+---------------------+ | start | type | end | +---------------------+------+---------------------+ | 2014-05-22 09:16:24 | 30 | 2014-05-22 09:46:24 | | 2014-05-22 09:56:24 | 20 | 2014-05-22 10:16:24 | +---------------------+------+---------------------+ Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/#findComment-1480473 Share on other sites More sharing options...
will35010 Posted May 23, 2014 Author Share Posted May 23, 2014 if those values are in the database you can do it the query SELECT start , type , start + INTERVAL type MINUTE as end FROM testtime; +---------------------+------+---------------------+ | start | type | end | +---------------------+------+---------------------+ | 2014-05-22 09:16:24 | 30 | 2014-05-22 09:46:24 | | 2014-05-22 09:56:24 | 20 | 2014-05-22 10:16:24 | +---------------------+------+---------------------+ Yeah, they are in the db, but I'm building this app with laravel 4. I'm using the query builder and eloquent so I'm trying to do it in the code to avoid complicating the query since I'm new to the framework. Quote Link to comment https://forums.phpfreaks.com/topic/288678-trying-to-use-strtotime/#findComment-1480557 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.