0

I'm recieving a timestamp with 3 hours more than I need

$time = '2019-04-10 15:42:05'

I need to decrease 3 hours to that variable $time, so I get:

2019-04-10 12:42:05

Pepemujica
  • 123
  • 7
  • @lovelace in that post you use the current time, I need to modify a variable with other timestamp – Pepemujica Apr 10 '19 at 18:46
  • `I'm receiving a timestamp with 3 hours more than I need` - from where, how is it created. It may be better to solve the root cause, such as the DB timezone (which is separate from PHP's timezone, one reason I never use `NOW()` etc.) - instead of band-aiding the problem. – ArtisticPhoenix Apr 10 '19 at 18:48
  • @ArtisticPhoenix since an external source is generating the date value, I can't modify it that way – Pepemujica Apr 10 '19 at 18:53
  • `$time = (new DateTime('2019-04-10 15:42:05'))->modify('-3 hours')->format('Y-m-d H:i:s');` ~ simple. [Sandbox](http://sandbox.onlinephpfunctions.com/code/e551d4cbb4db35486396703b0cf355df76d2b7bf) – ArtisticPhoenix Apr 10 '19 at 18:57
  • @ArtisticPhoenix thanks, I solved loke this: $new_date = date('Y-m-d H:i',strtotime('-3 hour',strtotime($date']))); With "modify" I had some problems. – Pepemujica Apr 10 '19 at 19:13
  • `I had some problems` ~ not sure what you mean, it should work (as demonstrated in the sandbox). Anyway glad you got if fixed. – ArtisticPhoenix Apr 10 '19 at 19:21

0 Answers0