2

I am trying to figure out how to easily add minutes to a timestamp in php.

I can do this easily in SQL such as select now() + interval '60 minutes' or using the DATEADD function, however I am not sure how to easily do this in PHP.

I have a date variable that I call as:

$date = date("Y-m-d H:i:s");

And now I just need to add or subtract time from this.

Can anybody help?

Thanks!

Walker Farrow
  • 3,579
  • 7
  • 29
  • 51

2 Answers2

11

You could use strtotime() like this:

$date = date('Y-m-d H:i:s', strtotime('now +60 minutes'));

Which would give you the date 60 minutes in the future formatted the way you'd like.

WWW
  • 9,734
  • 1
  • 29
  • 33
1

If you have the timestamp is like this

$tmt += 2 * 60 * 1000; $date= date("Y-m-d H:i:s", $tmt);

Try this

sdelcueto
  • 43
  • 7