I am calling some data from a simple SELECT query where the row contains three fields, start_time(DATETIME)
, end_time(DATETIME)
& reopen_time(DATETIME)
.
I am trying to work out the time between both the start_time
and end_time
& also between the start_time
& reopen_time
if this is a case. The way I am going to determine is by another column called complete
, which sets a value of either 1 or 0. It will calculate the start_time
and end_time
IF the complete value is 1 and start_time
and reopen_time
is value is 0.
Now, my PHP looks like the following so far; I am looking for somebody to help by casing and eye:
$id=$_GET['id']; //this grabs the id from the previous page depending on which task is clicked.
$sql = "SELECT * FROM to_do_list WHERE id=$id";
$result = mysqli_query($db, $sql);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$date1 = $row["start_time"];
$date2 = $row["end_time"];
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days\n", $years, $months, $days);
}
} else {
echo "There are no tasks!";
}
Now, the result I get back is: 0 years, 0 months, 0 days but there isn't an error. I am presuming the format of the data from the database is maybe incorrect?