Jump to content

trying to use strtotime


will35010
Go to solution Solved by 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

  • Solution

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.