0

I am making a program in which my end time is set. say for today end time is set to "2015-08-23 22:15:00".

Now if a customer buy a service of 60 minutes then I want to send him message to reach venue before "2015-08-23 22:15:00" ( -60 min ) means at "2015-08-23 21:15:00". So how can I subtract time in above manner.

I got a solution for this link.

It is working fine for

echo date('Y-m-d H:i:s', strtotime('-60 minutes'));

but not for

echo date('2015-08-23 22:15:00', strtotime('-60 minutes'));
Community
  • 1
  • 1

2 Answers2

1

You are using date in a wrong way. This is what you want:

echo date('Y-m-d H:i:s', strtotime('2015-08-23 22:15:00') - 60 * 60);
Ahmad
  • 5,551
  • 8
  • 41
  • 57
-1

I would recommend using DateTime class for that and modify the set time: http://php.net/manual/de/datetime.modify.php

$date = new DateTime('2015-08-23 22:15:00');
$date->modify('-60 minutes'); // Or $date->modify('-1 hour');
Tyr
  • 2,810
  • 1
  • 12
  • 21
  • Why do you think this is the right way? (I didn't downvote!) – Ahmad Aug 22 '15 at 13:03
  • Because you can cast nearly every format into a datetime object, It's save and easy to use modifying anything you need without making calculations by yourself, easy to check diffs between dates. Plus it's using locatization, considering leap years and much more. There is no need to cast a date into a timestamp to make another date. Thats so 2001.... ;) – Tyr Aug 22 '15 at 13:48
  • But I prefer to use the old method, because a lot of servers already don't have new versions of php, and they don't support this things. Some of things you said are right, but some of them are not. Anyway... – Ahmad Aug 22 '15 at 13:53