Search code examples
phptimecountdown

Add 3 hours to date from server


I've been trying to add 3 hours to a date set by a server. In the below example, I have filled out the $date_time and $id variables with pre-set content to avoid going into server details.

$date_time = "2015-10-21 21:01:00";

$id = 10;

$new_date = $date_time->modify("+3 hours"); 

$db->query("UPDATE prizes SET date='$new_date' WHERE id='$id'"); 

Why is this not working? This code is for a content site that adds 3 hours to it's countdown once someone wins.

UPDATE: Inserting variable into hours section I've tried this: $new_date = $date_time->modify("+{$hours} hours");

What am I doing wrong?


Solution

  • PHP doesn't know that your string is a date.

    $date_time = date('Y-m-d h:i:s', strtotime("2015-10-21 21:01:00"));