Jump to content

trying to use strtotime


will35010

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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! :)

Link to comment
Share on other sites

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 |
+---------------------+------+---------------------+
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.