-3

Hello My question is simple, Please let me know how i can subtract 30 minutes from a time my code is :

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


        $d_newdate = strtotime($endDate);
        $d_newdate1 = $d_newdate - ('30 minutes');
        echo $d_newdate2 = date("Y-m-d H:i:s", $d_newdate1);die("workings");

This code is adding one hour in time its wrong.i want to subtract 30 minutes.

user1990386
  • 23
  • 1
  • 11
  • 5
    possible duplicate of [PHP, subtract minutes](http://stackoverflow.com/questions/17717911/php-subtract-minutes) – Saty Sep 07 '15 at 07:19
  • 1
    Man... Just google "how i can subtract 30 minutes from a time my code" and the first entry will take you to @Saty link. Google your own question. – Amarnasan Sep 07 '15 at 07:23

3 Answers3

1
$date = '2015-08-02 15:30:00';
echo $date."<br>";
echo date('Y-m-d H:i:s',strtotime("-30 minutes",strtotime($date)));
Shailesh Katarmal
  • 2,757
  • 1
  • 12
  • 15
0
echo date("Y-m-d H:i:s")."<br>";
echo date("Y-m-d H:i:s",strtotime('-30 minutes'));
Disha V.
  • 1,834
  • 1
  • 13
  • 21
0

Try to use this

$d_newdate = strtotime($endDate);

$d_newdate1 = $d_newdate - (30 * 60);

$new_time = date("Y-m-d H:i:s", $d_newdate1);
Yatin Khullar
  • 1,580
  • 1
  • 12
  • 26
  • Its working fine for me as I tested before posting here. What problem you are facing? are you getting right value in your variable `$endDate` – Yatin Khullar Sep 07 '15 at 07:39
  • I resolve this .now my new query is how i can retrieve all the records from data base in between two date time my query is : SELECT * FROM `appointment` WHERE `ap_datetime` = '2015-09-08 01:30:00' AND (`cur_datetime` BETWEEN '2015-09-08 01:30:00' AND '2015-09-08 02:30:00') – user1990386 Sep 07 '15 at 09:19