0

In the database it is set for current_timestamp I am creating a script to run every hour that will compare the time from the Database then from local server see if it has been more than one hour so far I have this but confused where to go from here:

<?php
require('../config/dbconfig.php');
$sql = "SELECT * FROM stocks";
$result = mysqli_query($dbconfig,$sql);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
    $time = $row["TimeBought"];
}
$Time = date("Y-m-d H:i:s",$time);
$DateTime = time();
$NewTime = strtotime($Time);

What should I do from here?

Paul Brennan
  • 73
  • 1
  • 3
  • 11
  • This is a commonly asked question. Here is a good answer: http://stackoverflow.com/questions/23813201/datetime-comparison-php-mysql – RED MONKEY Oct 06 '16 at 16:31

1 Answers1

0

It is better to use DateTime object instead of date function.

$now = new DateTime();
$date = new DateTime('2014-06-04');

if ($now > $date) {
    echo 'The date is in the past.';
} else {
    echo 'The date is in the future.';
}
xpuc7o
  • 333
  • 3
  • 15