-1

So I'm doing a URL that expires and here's a some code

//DB query
$stmt = $con->prepare("SELECT token_created_at from reset WHERE token = :urltoken");
$stmt->bindValue(':urltoken', $_GET['token']);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while($row = $stmt->fetch()) {
     $token_created_at = $row['token_created_at'];
}

$expires_at = $token_created_at->modify('+1 hour');

//Return current time to match
$current_time = date('m-d-Y H:i:s ', time());

The issue is here's the error I get

( ! ) Fatal error: Call to a member function modify() on a non-object in /Users/matt/Desktop/Likes/forgot/activate.php on line 18

Line 18 is

$expires_at = $token_created_at->modify('+1 hour');

So if I can't do it this way, how would I do it?

1 Answers1

0

Obviously $token_created_at is just a string and not an object. For using modify of DateTime class (I think it is) you should first create DateTime object:

$my_dt = new DateTime($token_created_at);
$expires_at = $my_dt->modify(' + some time');
u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • 1
    Well I then get `Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (06-28-2014 07:43:58 ) at position 0 (0): Unexpected character` on the new object –  Jun 28 '14 at 11:59
  • This is my time format `06-28-2014 07:43:58` –  Jun 28 '14 at 12:20