-1

I am trying to add 55 minutes to a set time stored in the database. I am running an MySQL Query to get the time information. This is stored in the PHP Script as $row['login_time'].

If is getting stored in the database in the format like 2013-04-25 22:48:53 EDT.

I am trying to add 55 minutes to this time.

I have the following script but it is showing a value in 1969.

$seconds = 55 * 60;
echo date("Y-m-d H:i:s", $row['login_time'] + $seconds);
evanvee
  • 305
  • 2
  • 7
  • 18

3 Answers3

2

You should convert the DATETIME field to the value in seconds, you can use the php function strtotime

$seconds = 55 * 60;
echo date("Y-m-d H:i:s", strtotime($row['login_time']) + $seconds);
Miguel G. Flores
  • 802
  • 7
  • 21
0

You need to add the seconds after converting the date to a UNIX timestamp.

$seconds = 55 * 60;
$timestamp = strtotime(date("Y-m-d H:i:s", $row['login_time'])) + $seconds;
echo $timestamp;
Cory Shaw
  • 1,130
  • 10
  • 16
0

No need to get PHP involved:

UPDATE yourtable
SET timefield = timefield + INTERVAL 55 MINUTE

or

...
SET timefield = DATE_ADD(timefield, INTERVAL 55 MINUTE)
Marc B
  • 356,200
  • 43
  • 426
  • 500